@leaveye
2019-01-23T15:46:29.000000Z
字数 2151
阅读 885
NSIS
反馈
解决
PackSettings.nsh 中:
!define AppIcon "app.icon" ; 在 dist文件夹中
PackMain.nsi 中:
; 在 Name 和 Caption 的下面添加
!ifdef AppIcon
Icon "${AppRoot}\${AppIcon}"
!endif
在其它创建快捷方式的位置,指定使用它,如:
; 自动启动快捷方式。
SetOutPath $INSTDIR\${TOMCAT_SubDir}
CreateShortcut "$SMPROGRAMS\Startup\${Product}.lnk" "$INSTDIR\${TOMCAT_SubDir}\bin\startup.bat" "" "$INSTDIR\${AppIcon}" 0 SW_SHOWMINIMIZED
这种方式就无需在启动里加快捷方式了。是 Apache 官方推荐的方法。
首先在 tomcat\bin
下创建个 _helper.bat
脚本文件:
@echo off
if ""%1""==""--install"" goto to_install
if ""%1""==""--uninstall"" goto to_uninstall
if ""%1""==""--usage"" goto to_usage
if ""%1""=="""" goto to_usage
goto to_prompt
rem ============================================
:to_prompt
echo "ERR: unknown option '%1'" >&2
:to_usage
echo "_helper --install"
echo "_helper --uninstall"
echo "_helper --usage"
goto _end
rem ============================================
:to_install
call "setenv.bat"
rem 注册系统服务
call service.bat install "%SERVICE_NAME%"
rem 设置服务自动启动
sc config "%SERVICE_NAME%" start= auto
goto _end
rem ============================================
:to_uninstall
call "setenv.bat"
rem 删除服务
echo wait...
tomcat8.exe //DS//"%SERVICE_NAME%"
goto _end
rem ============================================
:_end
然后安装服务这样写:
; 注册系统服务。随系统自启。
SetOutPath $INSTDIR\${TOMCAT_SubDir}\bin
ExecWait '"$INSTDIR\${TOMCAT_SubDir}\bin\_helper.bat" --install'
在删除服务里这样写:
; 删除系统服务。可能需要稍稍等它停止服务。
StrCpy $OUTDIR $INSTDIR\${TOMCAT_SubDir}\bin
ExecWait '"$INSTDIR\${TOMCAT_SubDir}\bin\_helper.bat" --uninstall'
更新:记得在生成 setenv.bat
的段落,参照 JRE_HOME
设置下环境变量 SERVICE_NAME
。为服务命名。
参考
额外安装一个只有一行的 invisible.vbs
文件:
args = """" & WScript.Arguments(0) & """"
args = args & " " & """" & WScript.Arguments(1) & """"
args = args & " " & """" & WScript.Arguments(2) & """"
' 假如被调用的批处理最多有 X 个参数,上面的就要累计到 Arguments(X)
CreateObject("Wscript.Shell").Run args, 0, False
假定你安装到了 $INSTDIR
。
然后在执行某个 bat
脚本的时候:
; 从
ExecWait '"xxx.bat" ...'
; 改成
ExecWait '"$SYSDIR\wscript.exe" "$INSTDIR\invisible.vbs" "xxx.bat" ...'
参考:
- Run a batch file in a completely hidden way: https://superuser.com/a/62646