NsSCM plug-in: Difference between revisions
From NSIS Wiki
Jump to navigationJump to search
m (Updated author and download links, and changed format of some pages.) |
|||
(13 intermediate revisions by 8 users not shown) | |||
Line 1: | Line 1: | ||
{{PageAuthor|sl}} | |||
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 == | == Links == | ||
<attach>NsSCM.zip</attach> | <attach>NsSCM.zip</attach> The ZIP file containing a precompiled plugin DLL (to be saved in NSIS' plugin directory) and the sources. | ||
== Short Reference == | |||
Available commands: | |||
== The Script == | <highlight-nsis> | ||
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] | |||
</highlight-nsis> | |||
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 | |||
**272 - service with Desktop Interaction | |||
* 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. | |||
== The Sample Script == | |||
<highlight-nsis> | <highlight-nsis> | ||
; Turn off old selected section | ; Turn off old selected section | ||
; Methods: | ; Methods: | ||
; 1 str 2 str 3 num 4 num 5 str 6 str 7 str | ; 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] | ; [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] | nsSCM::Install /NOUNLOAD [parameters] | ||
Pop $0 ; return error/success | Pop $0 ; return error/success | ||
Line 38: | Line 82: | ||
; Samples: | ; Samples: | ||
; Driver (boot stage starting) | ; Driver (boot stage starting) | ||
nsSCM::Install /NOUNLOAD "XXX" "XXX driver" 1 0 "$SYSDIR\drivers\XXX.sys" "" "" | nsSCM::Install /NOUNLOAD "XXX" "XXX driver" 1 0 \ | ||
"$SYSDIR\drivers\XXX.sys" "" "" "" "" | |||
Pop $0 ; return error/success | Pop $0 ; return error/success | ||
; Driver (sscm stage starting) | ; Driver (sscm stage starting) | ||
nsSCM::Install /NOUNLOAD "XXX" "XXX driver" 1 1 "$SYSDIR\drivers\XXX.sys" "" "" | nsSCM::Install /NOUNLOAD "XXX" "XXX driver" 1 1 \ | ||
"$SYSDIR\drivers\XXX.sys" "" "" "" "" | |||
Pop $0 ; return error/success | Pop $0 ; return error/success | ||
; Driver (manual starting) | ; Driver (manual starting) | ||
nsSCM::Install /NOUNLOAD "XXX" "XXX driver" 1 3 "$SYSDIR\drivers\XXX.sys" "" "" | nsSCM::Install /NOUNLOAD "XXX" "XXX driver" 1 3 \ | ||
"$SYSDIR\drivers\XXX.sys" "" "" "" "" | |||
Pop $0 ; return error/success | Pop $0 ; return error/success | ||
; Service (auto starting) | ; Service (auto starting) | ||
nsSCM::Install /NOUNLOAD "XXX" "XXX service" 16 2 "$PROGRAMFILES\${PRJ_NAME}\XXX.exe" "" "" | nsSCM::Install /NOUNLOAD "XXX" "XXX service" 16 2 \ | ||
"$PROGRAMFILES\${PRJ_NAME}\XXX.exe" "" "" "" "" | |||
Pop $0 ; return error/success | |||
; Service (auto starting WITH DESKTOP INTERACTION) | |||
nsSCM::Install /NOUNLOAD "XXX" "XXX service" 272 2 \ | |||
"$PROGRAMFILES\${PRJ_NAME}\XXX.exe" "" "" "" "" | |||
Pop $0 ; return error/success | Pop $0 ; return error/success | ||
; Service (manual starting) | ; Service (manual starting) | ||
nsSCM::Install /NOUNLOAD "XXX" "XXX service" 16 3 "$PROGRAMFILES\${PRJ_NAME}\XXX.exe" "" "" | nsSCM::Install /NOUNLOAD "XXX" "XXX service" 16 3 \ | ||
"$PROGRAMFILES\${PRJ_NAME}\XXX.exe" "" "" "" "" | |||
Pop $0 ; return error/success | Pop $0 ; return error/success | ||
Line 67: | Line 121: | ||
</highlight-nsis> | </highlight-nsis> | ||
[[Category:Plugins]] |
Latest revision as of 21:14, 19 March 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
- 272 - service with Desktop Interaction
- 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.
The Sample Script
; 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 (auto starting WITH DESKTOP INTERACTION) nsSCM::Install /NOUNLOAD "XXX" "XXX service" 272 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" 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