![](/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.