6
votes

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.

3
Could you post an excerpt of the failing script to show how the parameters of the Exec statement? Do you have any warning in the makensis output? - Seki
ExecWait '"C:\Windows\System32\sc.EXE" "Test Service"' Exec $PROGRAMFILES\Example1\xxxx.EXE - Sujeeth Damodharan
Do not confound the service name and the display name: Test Service as service name is not correct due to the space - Seki
Please post the exact syntax you use in your sc command. To register a service, you need sc create ..., sc service name is not a working command - Seki
i cant(dono)able to update my script its saying error seki. you understood my problem rite?? you can send me example script it will help me i hope thanks - Sujeeth Damodharan

3 Answers

7
votes

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
votes

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

-1
votes

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