Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 525
Sujeeth Damodharan Avatar asked Jul 22 '13 11:07

Sujeeth Damodharan


2 Answers

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.

like image 169
Seki Avatar answered Nov 20 '22 00:11

Seki


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

like image 38
taras Avatar answered Nov 19 '22 22:11

taras