How to install application as windows service using NSIS script
Asked Answered
H

3

8

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.

Hines answered 22/7, 2013 at 11:51 Comment(6)
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?Anallese
ExecWait '"C:\Windows\System32\sc.EXE" "Test Service"' Exec $PROGRAMFILES\Example1\xxxx.EXEHines
Do not confound the service name and the display name: Test Service as service name is not correct due to the spaceAnallese
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 commandAnallese
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 thanksHines
You seem to have a problem for configuring a new service. For now, I am unsure if you have a problem inside your NSIS script, or with the sc command that you use. Try the sc command with correct parameters directly in a command prompt. Does it configure the service, or do you have an error message (if so, what message)?Anallese
A
9

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.

Anallese answered 22/7, 2013 at 12:51 Comment(5)
i cant get it Seki... after the installation my service should be in the windows service. i can able to stop or start by using that entry please help me clearly thanks... what does it means "C:\MyPath\MyService.exe"Hines
I have added the SimpleSC.dll into the NSIS folder and to which place i want to add this code in my script ???SimpleSC::InstallService "MyService" "My Service Display Name" "16" "2" "C:\MyPath\MyService.exe" "" "" "" Pop $0 ; returns an errorcode (<>0) otherwise success (0)Hines
@SujeethDamodharan Be aware that there's a function to look up error codes for you. You also need to make sure the user ahs the "Log on as a service" right - which is another function. Read the documentation for example of bothCispadane
I trying with this example , and i have probleme Plugin not found, cannot call SimpleSC::StartService,sorry i dont very googd in englishPablopabon
Note: The SImple Service plugin does not work with Unicode NSISZworykin
D
6

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

Dentition answered 24/3, 2021 at 10:16 Comment(0)
V
-1

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
Vested answered 4/9, 2018 at 6:9 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.