NsSCM plug-in: Difference between revisions

From NSIS Wiki
Jump to navigationJump to search
m (Service Control Manager plugin (install services and drivers on NT/2K/XP) moved to NsSCM plug-in)
Line 42: Line 42:




== The Sample Script ==
qewrqwer
<highlight-nsis>
; Turn off old selected section
; Methods:
  ; 1 str 2 str 3 num 4 num 5 str 6 str 7 str 8 str 9 str
  ; [name of service: startstop name] [name to display: display in SCM]
  ;    [service type] [start type] [service's binary:filepath]
  ;    [load order group: name] [dependencies: name] [account: name] [password: str]
  nsSCM::Install /NOUNLOAD [parameters]
  Pop $0 ; return error/success
 
  ; [name of service:startstop name]
  nsSCM::Start /NOUNLOAD [parameters]
  Pop $0 ; return error/success
 
  ; [name of service:startstop name]
  nsSCM::QueryStatus /NOUNLOAD [parameters]
  Pop $0 ; return error/success
  Pop $1 ; return service status
 
  ;!define SERVICE_STOPPED                0x00000001
  ;!define SERVICE_START_PENDING          0x00000002
  ;!define SERVICE_STOP_PENDING          0x00000003
  ;!define SERVICE_RUNNING                0x00000004
  ;!define SERVICE_CONTINUE_PENDING      0x00000005
  ;!define SERVICE_PAUSE_PENDING          0x00000006
  ;!define SERVICE_PAUSED                0x00000007
 
  ; [name of service:startstop name]
  nsSCM::Stop /NOUNLOAD [parameters]
  Pop $0 ; return error/success
 
  ; [name of service:startstop name]
  nsSCM::Remove /NOUNLOAD [parameters]
  Pop $0 ; return error/success
 
; Samples:
  ; Driver (boot stage starting)
  nsSCM::Install /NOUNLOAD "XXX" "XXX driver" 1 0 \
                          "$SYSDIR\drivers\XXX.sys" "" "" "" ""
  Pop $0 ; return error/success
 
  ; Driver (sscm stage starting)
  nsSCM::Install /NOUNLOAD "XXX" "XXX driver" 1 1 \
                          "$SYSDIR\drivers\XXX.sys" "" "" "" ""
  Pop $0 ; return error/success
 
  ; Driver (manual starting)
  nsSCM::Install /NOUNLOAD "XXX" "XXX driver" 1 3 \
                          "$SYSDIR\drivers\XXX.sys" "" ""
  Pop $0 ; return error/success
 
  ; Service (auto starting)
  nsSCM::Install /NOUNLOAD "XXX" "XXX service" 16 2 \
                          "$PROGRAMFILES\${PRJ_NAME}\XXX.exe" "" ""
  Pop $0 ; return error/success
 
  ; Service (manual starting)
  nsSCM::Install /NOUNLOAD "XXX" "XXX service" 16 3 \
                          "$PROGRAMFILES\${PRJ_NAME}\XXX.exe" "" ""
  Pop $0 ; return error/success


   nsSCM::Start /NOUNLOAD "XXX"
   nsSCM::Start /NOUNLOAD "XXX"

Revision as of 12:50, 17 January 2006

Author: sl (talk, contrib)


nsSCM stands for Service Control Manager.

This plugin can be used to install/remove services, start or stop them and check their current status. Useful if you want to install a background service or a driver.

The new version fixes a bug which prevented nsSCM to install a service under a specified account.

Links

NsSCM.zip (8 KB) The ZIP file containing a precompiled plugin DLL (to be saved in NSIS' plugin directory) and the sources.

Short Reference

Available commands:

nsSCM::Install [name_of_service] [display_name] [service_type] [start_type] [service_commandline] [load_order_group] [dependencies] [account] [password]
nsSCM::Start [name_of_service] 
nsSCM::Stop [name_of_service] 
nsSCM::QueryStatus [name_of_service] 
nsSCM::Remove [name_of_service]

Parameters:

  • name_of_service - the name of the service used for Start/Stop commands and all further nsSCM commands
  • display_name - the name as shown in the service control manager applet in system control
  • service_type - one of the following codes
    • 1 - device driver
    • 16 - service
  • start_type - one of the following codes
    • 0 - driver boot stage start
    • 1 - driver sscm stage start
    • 2 - service auto start
    • 3 - driver/service manual start
  • service_commandline - the path to the binary including all necessary parameters
  • load_order_group - controls the order of service starts
  • dependencies - needed services, controls which services have to be started before this one
  • account - the account which should be used to run the service
  • password - password of the aforementioned account to be able to logon as a service

If you do not specify account/password, the local system account will be used to run the service.


qewrqwer

 nsSCM::Start /NOUNLOAD "XXX"
 Pop $0 ; return error/success
 nsSCM::QueryStatus /NOUNLOAD
 Pop $0 ; return error/success
 Pop $1 ; return service status
 IntCmp $1 4 lbl_Return ; check on running

</highlight-nsis>