6

如何使用 NSIS 脚本将应用程序安装为 Windows 服务?

我在脚本中使用了这个命令,Exec '"sc.exe"但是安装后我在 Windows 服务中找不到任何与之相关的服务,所以请帮助我,谢谢。

4

3 回答 3

7

也许 NSIS简单服务插件可以帮助你。语法很简单

SimpleSC::InstallService "MyService" "My Service Display Name" "16" "2" "C:\MyPath\MyService.exe" "" "" ""
Pop $0 ; returns an errorcode (<>0) otherwise success (0)

这里的示例将服务安装为 ServiceType 自己的进程 + StartType 自动 + NoDependencies + 作为系统帐户登录。有关幻数的含义,请参阅随附的帮助。

wiki 展示了使用 NSIS 处理服务的5 种其他方法。

于 2013-07-22T12:51:49.607 回答
2

如 NSIS 网站所述,有多个插件

对我来说,这似乎是不必要的复杂,所以我最终sc直接使用工具。一个命令很简单:

!define appName "theApp.exe"
!define displayName "My Awesome Service"
!define serviceName "MyAwesomeService"

ExecWait 'sc create ${serviceName} error= "severe" displayname= "${displayName}" type= "own" start= "auto" binpath= "$INSTDIR\${appName}"'

此处sc create提供的完整参数列表

于 2021-03-24T10:16:11.620 回答
-1

下面是首先停止服务、卸载以前版本、删除表单注册表然后安装新副本的脚本。

Section "Mobile Interface" 

  SimpleSC::StopService "MobileInterface" "1" "60"
  SimpleSC::RemoveService "MobileInterface"
  DeleteRegKey /ifempty HKLM "MobileInterface"
  RMDIR /r "$INSTDIR\MobileInterface\"

  SetOutPath "$INSTDIR\MobileInterface"
   # define what to install and place it in the output path
 File "D:\NCS.Sentinel\NCS.Sentinel.MobileWebSvc\bin\Release\"

 SimpleSC::InstallService "MobileInterface" "MobileInterface" "16" "2" "$INSTDIR\MobileInterface\NCS.Sentinel.MobileWebSvc.exe" "" "" ""
 Pop $0 ; returns an errorcode (<>0) otherwise success (0)
 SimpleSC::StartService "MobileInterface" "" "100"

#WriteRegStr HKLM "D:\NCS.Sentinel\NCS.Sentinel.MobileWebSvc\bin\Release\NCS.Sentinel.MobileWebSvc.exe" 

  WriteUninstaller "$INSTDIR\Uninstall.exe"

  ; Store installation folder
  ;WriteRegStr HKCU "Software\Mobile Interface" "" $INSTDIR



SectionEnd
于 2018-09-04T06:09:55.170 回答