NSIS Simple Service Plugin: Difference between revisions
From NSIS Wiki
Jump to navigationJump to search
m (→Changelog) |
|||
Line 60: | Line 60: | ||
<highlight-nsis> | <highlight-nsis> | ||
; Install a service - StartType automatic - NoDependencies - Logon as System Account | ; Install a service - StartType automatic - NoDependencies - Logon as System Account | ||
; NOTE: If you need dependencies it currently only supports one dependency. | |||
; In order to support multiple the source code for the 'installservice' | |||
; function in the Delphi code that implements this plugin needs updated | |||
; to automatically search for a given separator character (I'd suggest | |||
; '/' forward-slash) and replace it with a null character (0x00)). The | |||
; 'createservice' Win32 API call that 'installservice' calls expects the | |||
; dependencies list to be a "char**" (in C terms). In other words, a | |||
; double null-terminated list of strings separated by nulls. I don't have | |||
; a Delphi compiler available right now, so I can't fix this now. I'm | |||
; gonna use the "ExecCmd" plugin along with the "sc" command-line program | |||
; to install my multiple dependency services for now. | |||
; -- Gerald E. Butler (http://bffoss.com) | |||
SimpleSC::InstallService "MyService" "My Service Display Name" "2" "C:\MyPath\MyService.exe" "" "" "" | SimpleSC::InstallService "MyService" "My Service Display Name" "2" "C:\MyPath\MyService.exe" "" "" "" | ||
Pop $0 ; return error(1)/success(0) | Pop $0 ; return error(1)/success(0) |
Revision as of 16:59, 10 December 2007
This plugin contains basic service functions like start, stop the service or checking the service status. It also contains advanced service functions for example setting the service description, changed the logon account, granting or removing the service logon privilege.
This plugin is using the MPL License or alternatively the LGPL License.
Links
NSIS_Simple_Service_Plugin_1.04.zip (37 KB) The ZIP file containing a precompiled plugin DLL (to be saved in NSIS' plugin directory) and the sources.
Short Reference
SimpleSC::InstallService [name_of_service] [display_name] [start_type] [service_commandline] [dependencies] [account] [password] SimpleSC::RemoveService [name_of_service] SimpleSC::StartService [name_of_service] SimpleSC::StopService [name_of_service] SimpleSC::PauseService [name_of_service] SimpleSC::ContinueService [name_of_service] SimpleSC::RestartService [name_of_service] SimpleSC::ExistsService [name_of_service] SimpleSC::GetServiceDisplayName [name_of_service] SimpleSC::GetServiceName [display_name] SimpleSC::GetServiceStatus [name_of_service] SimpleSC::GetServiceBinaryPath [name_of_service] SimpleSC::SetServiceDescription [name_of_service] [service_description] SimpleSC::SetServiceStartType [name_of_service] [start_type] SimpleSC::SetServiceLogon [name_of_service] [account] [password] SimpleSC::GrantServiceLogonPrivilege [account] SimpleSC::RemoveServiceLogonPrivilege [account] SimpleSC::ServiceIsPaused [name_of_service] SimpleSC::ServiceIsRunning [name_of_service] SimpleSC::ServiceIsStopped [name_of_service]
Parameters:
- name_of_service - the name of the service used for Start/Stop commands and all further commands
- display_name - the name as shown in the service control manager applet in system control
- start_type - one of the following codes
- 0 - driver boot stage start
- 1 - driver scm stage start
- 2 - service auto start
- 3 - driver/service manual start
- 4 - driver/service disabled
- service_commandline - the path to the binary including all necessary parameters
- dependencies - needed services, controls which services have to be started before this one
- account - the username/account which should be used
- 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
- service_description - the description as shown in the service control manager applet in system control
The Sample Script
; Install a service - StartType automatic - NoDependencies - Logon as System Account ; NOTE: If you need dependencies it currently only supports one dependency. ; In order to support multiple the source code for the 'installservice' ; function in the Delphi code that implements this plugin needs updated ; to automatically search for a given separator character (I'd suggest ; '/' forward-slash) and replace it with a null character (0x00)). The ; 'createservice' Win32 API call that 'installservice' calls expects the ; dependencies list to be a "char**" (in C terms). In other words, a ; double null-terminated list of strings separated by nulls. I don't have ; a Delphi compiler available right now, so I can't fix this now. I'm ; gonna use the "ExecCmd" plugin along with the "sc" command-line program ; to install my multiple dependency services for now. ; -- Gerald E. Butler (http://bffoss.com) SimpleSC::InstallService "MyService" "My Service Display Name" "2" "C:\MyPath\MyService.exe" "" "" "" Pop $0 ; return error(1)/success(0) ; Remove a service SimpleSC::RemoveService "MyService" Pop $0 ; return error(1)/success(0) ; Start a service SimpleSC::StartService "MyService" Pop $0 ; return error(1)/success(0) ; Stop a service SimpleSC::StopService "MyService" Pop $0 ; return error(1)/success(0) ; Pause a service SimpleSC::PauseService "MyService" Pop $0 ; return error(1)/success(0) ; Continue a service SimpleSC::ContinueService "MyService" Pop $0 ; return error(1)/success(0) ; Restart a service SimpleSC::RestartService "MyService" Pop $0 ; return error(1)/success(0) ; Check if the service exists SimpleSC::ExistsService "MyService" Pop $0 ; return service exists(1)/service doesn´t exists (0) ; Get the displayname of a service SimpleSC::GetServiceDisplayName "MyService" Pop $0 ; return error(1)/success(0) Pop $1 ; return the displayname of the service ; Get the servicename of a service by the displayname SimpleSC::GetServiceName "MyService" Pop $0 ; return error(1)/success(0) Pop $1 ; return the servicename of the service ; Get the current status of a service SimpleSC::GetServiceStatus "MyService" Pop $0 ; return error(1)/success(0) Pop $1 ; return the status of the service ; Valid values are: ; 1 - SERVICE_STOPPED ; 2 - SERVICE_START_PENDING ; 3 - SERVICE_STOP_PENDING ; 4 - SERVICE_RUNNING ; 5 - SERVICE_CONTINUE_PENDING ; 6 - SERVICE_PAUSE_PENDING ; 7 - SERVICE_PAUSED ; Get the binary path of a service SimpleSC::GetServiceBinaryPath "MyService" Pop $0 ; return error(1)/success(0) Pop $1 ; return the binary path of the service ; Set the description of a service (Not supported on Windows NT 4.0) SimpleSC::SetServiceDescription "MyService" "Sample Description" Pop $0 ; return error(1)/success(0) ; Set the starttype to automatic of a service SimpleSC::SetServiceStartType "MyService" "2" Pop $0 ; return error(1)/success(0) ; Sets the service logon to a user and grant the user the "SeServiceLogonPrivilege" SimpleSC::SetServiceLogon "MyService" "MyServiceUser" "MyServiceUserPassword" Pop $0; return error(1)/success(0) StrCmp $0 +1 Done ; If successful grant the service logon privilege to "MyServiceUser" ; Note: Every serviceuser must have the ServiceLogonPrivilege to start the service SimpleSC::GrantServiceLogonPrivilege "MyServiceUser" Pop $0; return error(1)/success(0) Done: ; Remove the "SeServiceLogonPrivilege" from a user SimpleSC::RemoveServiceLogonPrivilege "MyServiceUser" Pop $0; return error(1)/success(0) ; Check if the service is paused SimpleSC::ServiceIsPaused "MyService" Pop $0; return error(1)/success(0) Pop $1; return 1 (service is paused) - return 0 (service is not paused) ; Check if the service is running SimpleSC::ServiceIsRunning "MyService" Pop $0; return error(1)/success(0) Pop $1; return 1 (service is running) - return 0 (service is not running) ; Check if the service is stopped SimpleSC::ServiceIsStopped "MyService" Pop $0; return error(1)/success(0) Pop $1; return 1 (service is stopped) - return 0 (service is not stopped)
Changelog
- From Version 1.03 to Version 1.04
- Fixed bug for possible endless loops. This concerns to the functions StartService, StopService, ContinueService and PauseService.
- From Version 1.02 to Version 1.03
- Added function SimpleSC::GetServiceBinaryPath to get the binary path of a specified service.
- From Version 1.01 to Version 1.02
- Changed wrong documentation informations about the functions SimpleSC::InstallService and SimpleSC::RemoveService
- From Version 1.0 to Version 1.01
- Changed wrong status-results in Readme.txt. This concerns to the functions ServiceIsPaused, ServiceIsRunning and ServiceIsStopped
- Changed the access privileges of the plugin. The plugin now uses the lowest privlege of each function to execute.
Important Notes
- The functions "GetServiceDisplayName" or "SetServiceDisplayName" are only available on systems higher than Windows NT.
- If you change the logon of an service to a new user you have to grant him the Service Logon Privilege. Otherwise the service cannot be started by the user you have assigned.
- If you have any suggestions, comments or questions please mail me: mailto:rainer@speed-soft.de
- The functions StartService, StopService, PauseService and ContinueService uses a timeout of 30 seconds. This means the function must be executed within 30 seconds, otherwise the functions will return an error.