Sujeeth Damodharan
Sujeeth Damodharan

Reputation: 477

How to install application as windows service using NSIS script

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.

Upvotes: 8

Views: 16634

Answers (3)

taras
taras

Reputation: 3705

There are multiple plugins out there as stated on NSIS website

For me it seemed to be unnecessary complicated, so I ended up using sc tool directly. A command is quite simple:

!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}"'

A full list of sc create arguments available here

Upvotes: 6

Zaheer Abbas
Zaheer Abbas

Reputation: 31

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

Upvotes: -1

Seki
Seki

Reputation: 11465

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.

Upvotes: 9

Related Questions