![](/img/trans.png)
[英]Need a (script)procedure to install an application as windows service using NSIS script
[英]How to install application as windows service using NSIS script
如何使用 NSIS 脚本将应用程序安装为 Windows 服务?
我在脚本Exec '"sc.exe"
使用了这个命令,但安装后我在 Windows 服务中找不到任何与它相关的服务,所以请帮助我,谢谢。
也许 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 种方法。
如 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
参数的完整列表
下面是首先停止服务、卸载以前版本、删除表单注册表然后安装新副本的脚本。
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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.