How to install application as windows service using NSIS script

一世执手 提交于 2019-12-10 15:33:34

问题


How to install application as windows service using NSIS script?

I used this command in the script Exec '"sc.exe" but after installation i couldn't find any service in windows services related to it so help me thanks.


回答1:


Maybe that the NSIS Simple Service plugin can help you. The syntax is as simple as

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

Here the example install the service as ServiceType own process + StartType automatic + NoDependencies + Logon as System Account. Please refer to the accompanying help for the meaning of the magic numbers.

The wiki shows the 5 other methods to handle services with NSIS.




回答2:


Below is the scripts which first stops service, uninstalls previous version, remove form registry and then installs fresh copy.

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


来源:https://stackoverflow.com/questions/17786875/how-to-install-application-as-windows-service-using-nsis-script

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!