|
|
| (6 intermediate revisions by 2 users not shown) |
| Line 1: |
Line 1: |
| 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.
| | == Links == |
| | [https://github.com/Speed7811/nsis-simple-service-plugin GitHub repository] - source code, documentation and issue tracker |
|
| |
|
| | [https://github.com/Speed7811/nsis-simple-service-plugin/releases/latest Download the latest version] (ANSI and Unicode builds) |
|
| |
|
| This plugin is using the MPL License or alternatively the LGPL License.
| | == Description == |
| | | SimpleSC is an NSIS plugin to manage Windows services. It contains basic functions like installing, removing, starting or stopping a service and checking the service status, as well as advanced functions for example setting the service description, changing the logon account, configuring failure actions and granting or removing the service logon privilege. |
| | |
| == Links == | |
| <attach>NSIS_Simple_Service_Plugin_1.30.zip</attach> The ZIP file containing a precompiled plugin DLL (to be saved in NSIS' plugin directory) and the sources. If you update from a previous version it is strongly '''recommend''' to take look at the changelog.
| |
| | |
| == Donation ==
| |
| If you believe that I am doing a good job and you want to support me please [http://www.speed-soft.de/donation/index.php?language=en donate] any amount via PayPal.
| |
|
| |
|
| I'm impressed. You've really reaisd the bar with that.
| | == Installation == |
| | * ANSI build: copy SimpleSC.dll to Plugins\x86-ansi (NSIS 3) or Plugins (NSIS 2) |
| | * Unicode build: copy SimpleSC.dll to Plugins\x86-unicode (NSIS 3 with Unicode true) |
|
| |
|
| == The Sample Script == | | == Example == |
| <highlight-nsis> | | <highlight-nsis> |
| ; Install a service - ServiceType own process - StartType automatic - NoDependencies - Logon as System Account | | ; Install a service - ServiceType own process - StartType automatic - NoDependencies - Logon as System Account |
| Line 19: |
Line 17: |
| Pop $0 ; returns an errorcode (<>0) otherwise success (0) | | Pop $0 ; returns an errorcode (<>0) otherwise success (0) |
|
| |
|
| ; Install a service - ServiceType interact with desktop - StartType automatic - Dependencies on "Windows Time Service" (w32time) and "WWW Publishing Service" (w3svc) - Logon as System Account
| | ; Start a service |
| SimpleSC::InstallService "MyService" "My Service Display Name" "272" "2" "C:\MyPath\MyService.exe" "w32time/w3svc" "" ""
| |
| Pop $0 ; returns an errorcode (<>0) otherwise success (0)
| |
| | |
| ; Remove a service
| |
| SimpleSC::RemoveService "MyService"
| |
| Pop $0 ; returns an errorcode (<>0) otherwise success (0)
| |
| | |
| ; Start a service. Be sure to pass the service name, not the display name. | |
| SimpleSC::StartService "MyService" "" 30 | | SimpleSC::StartService "MyService" "" 30 |
| Pop $0 ; returns an errorcode (<>0) otherwise success (0) | | Pop $0 ; returns an errorcode (<>0) otherwise success (0) |
|
| |
|
| ; Start a service with two arguments "/param1=true" "/param2=1"
| | ; Stop a service and waits for file release |
| SimpleSC::StartService "MyService" "/param1=true /param2=1" 30
| |
| Pop $0 ; returns an errorcode (<>0) otherwise success (0)
| |
|
| |
| ; Start a service with two arguments "-p param1" "-param2"
| |
| SimpleSC::StartService "MyService" '"-p param1" -param2' 30
| |
| Pop $0 ; returns an errorcode (<>0) otherwise success (0)
| |
| | |
| ; Stop a service and waits for file release. Be sure to pass the service name, not the display name. | |
| SimpleSC::StopService "MyService" 1 30 | | SimpleSC::StopService "MyService" 1 30 |
| Pop $0 ; returns an errorcode (<>0) otherwise success (0) | | Pop $0 ; returns an errorcode (<>0) otherwise success (0) |
|
| |
|
| ; Stops two services and waits for file release after the last service is stopped | | ; Remove a service |
| SimpleSC::StopService "MyService1" 0 30
| | SimpleSC::RemoveService "MyService" |
| Pop $0 ; returns an errorcode (<>0) otherwise success (0)
| |
| SimpleSC::StopService "MyService2" 1 30
| |
| Pop $0 ; returns an errorcode (<>0) otherwise success (0)
| |
| | |
| ; Pause a service
| |
| SimpleSC::PauseService "MyService" 30 | |
| Pop $0 ; returns an errorcode (<>0) otherwise success (0) | | Pop $0 ; returns an errorcode (<>0) otherwise success (0) |
|
| |
| ; Continue a service
| |
| SimpleSC::ContinueService "MyService" 30
| |
| Pop $0 ; returns an errorcode (<>0) otherwise success (0)
| |
|
| |
| ; Restart a service
| |
| SimpleSC::RestartService "MyService" "" 30
| |
| Pop $0 ; returns an errorcode (<>0) otherwise success (0)
| |
|
| |
| ; Restart a service with two arguments "/param1=true" "/param2=1"
| |
| SimpleSC::RestartService "MyService" "/param1=true /param2=1" 30
| |
| Pop $0 ; returns an errorcode (<>0) otherwise success (0)
| |
|
| |
| ; Start a service with two arguments "-p param1" "-param2"
| |
| SimpleSC::RestartService "MyService" '"-p param1" -param2' 30
| |
| Pop $0 ; returns an errorcode (<>0) otherwise success (0)
| |
|
| |
| ; Check if the service exists
| |
| SimpleSC::ExistsService "MyService"
| |
| Pop $0 ; returns an errorcode if the service doesn´t exists (<>0)/service exists (0)
| |
|
| |
| ; Get the displayname of a service
| |
| SimpleSC::GetServiceDisplayName "MyService"
| |
| Pop $0 ; returns an errorcode (<>0) otherwise success (0)
| |
| Pop $1 ; returns the displayname of the service
| |
|
| |
| ; Get the servicename of a service by the displayname
| |
| SimpleSC::GetServiceName "MyService"
| |
| Pop $0 ; returns an errorcode (<>0) otherwise success (0)
| |
| Pop $1 ; returns the servicename of the service
| |
|
| |
| ; Get the current status of a service
| |
| SimpleSC::GetServiceStatus "MyService"
| |
| Pop $0 ; returns an errorcode (<>0) otherwise success (0)
| |
| Pop $1 ; return the status of the service (See "service_status" in the parameters)
| |
|
| |
| ; Get the description of a service
| |
| SimpleSC::GetServiceDescription "MyService"
| |
| Pop $0 ; returns an errorcode (<>0) otherwise success (0)
| |
| Pop $1 ; returns the description of the service
| |
|
| |
| ; Get the start type of the service
| |
| SimpleSC::GetServiceStartType "MyService"
| |
| Pop $0 ; returns an errorcode (<>0) otherwise success (0)
| |
| Pop $1 ; returns the start type of the service (see "start_type" in the parameters)
| |
|
| |
| ; Get the binary path of a service
| |
| SimpleSC::GetServiceBinaryPath "MyService"
| |
| Pop $0 ; returns an errorcode (<>0) otherwise success (0)
| |
| Pop $1 ; returns the binary path of the service
| |
|
| |
| ; Get the logon user of the service
| |
| SimpleSC::GetServiceLogon "MyService"
| |
| Pop $0 ; returns an errorcode (<>0) otherwise success (0)
| |
| Pop $1 ; returns the logon username of the service
| |
|
| |
| ; Get the failure configuration of a service
| |
| SimpleSC::GetServiceFailure "MyService"
| |
| Pop $0 ; returns an errorcode (<>0) otherwise success (0)
| |
| Pop $1 ; returns the reset period
| |
| Pop $2 ; returns the reboot message
| |
| Pop $3 ; returns the command
| |
| Pop $4 ; returns the first action (See "action_type_x" in the parameters)
| |
| Pop $5 ; returns the first action delay
| |
| Pop $6 ; returns the second action (See "action_type_x" in the parameters)
| |
| Pop $7 ; returns the second action delay
| |
| Pop $8 ; returns the third action (See "action_type_x" in the parameters)
| |
| Pop $9 ; returns the third action delay
| |
|
| |
| ; Get the failure flag configuration of a service
| |
| SimpleSC::GetServiceFailureFlag "MyService"
| |
| Pop $0 ; returns an errorcode (<>0) otherwise success (0)
| |
| Pop $1 ; returns the service flag
| |
|
| |
| ; Get the delayed auto-start configuration of a service
| |
| SimpleSC::GetServiceDelayedAutoStartInfo "MyService"
| |
| Pop $0 ; returns an errorcode (<>0) otherwise success (0)
| |
| Pop $1 ; returns the delayed auto-start configuration
| |
|
| |
| ; Set the description of a service
| |
| SimpleSC::SetServiceDescription "MyService" "Sample Description"
| |
| Pop $0 ; returns an errorcode (<>0) otherwise success (0)
| |
|
| |
| ; Set the starttype to automatic of a service
| |
| SimpleSC::SetServiceStartType "MyService" "2"
| |
| Pop $0 ; returns an errorcode (<>0) otherwise success (0)
| |
|
| |
| ; Sets the service binary path
| |
| SimpleSC::SetServiceBinaryPath "MyService" "C:\MySoftware\MyService.exe"
| |
| Pop $0 ; returns an errorcode (<>0) otherwise success (0)
| |
|
| |
| ; Sets the service logon to a user and grant the user the "SeServiceLogonPrivilege"
| |
| SimpleSC::SetServiceLogon "MyService" "MyServiceUser" "MyServiceUserPassword"
| |
| Pop $0 ; returns an errorcode (<>0) otherwise success (0)
| |
| IntCmp $0 0 +1 Done 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 ; returns an errorcode (<>0) otherwise success (0)
| |
| Done:
| |
|
| |
| ; Sets the service failure configuration - First action: Restart the service after one minute - Second action: Reboot the computer after five minutes
| |
| SimpleSC::SetServiceFailure "MyService" "0" "" "" "1" "60000" "2" "300000" "0" "0"
| |
| Pop $0 ; returns an errorcode (<>0) otherwise success (0)
| |
|
| |
| ; Sets the failure flag configuration of a service
| |
| SimpleSC::SetServiceFailureFlag "MyService" "1"
| |
| Pop $0 ; returns an errorcode (<>0) otherwise success (0)
| |
|
| |
| ; Sets the delayed auto-start configuration of a service
| |
| SimpleSC::SetServiceDelayedAutoStartInfo "MyService" "1"
| |
| Pop $0 ; returns an errorcode (<>0) otherwise success (0)
| |
|
| |
| ; Remove the "SeServiceLogonPrivilege" from a user
| |
| SimpleSC::RemoveServiceLogonPrivilege "MyServiceUser"
| |
| Pop $0 ; returns an errorcode (<>0) otherwise success (0)
| |
|
| |
| ; Check if the service is paused
| |
| SimpleSC::ServiceIsPaused "MyService"
| |
| Pop $0 ; returns an errorcode (<>0) otherwise success (0)
| |
| Pop $1 ; returns 1 (service is paused) - returns 0 (service is not paused)
| |
|
| |
| ; Check if the service is running
| |
| SimpleSC::ServiceIsRunning "MyService"
| |
| Pop $0 ; returns an errorcode (<>0) otherwise success (0)
| |
| Pop $1 ; returns 1 (service is running) - returns 0 (service is not running)
| |
|
| |
| ; Check if the service is stopped
| |
| SimpleSC::ServiceIsStopped "MyService"
| |
| Pop $0 ; returns an errorcode (<>0) otherwise success (0)
| |
| Pop $1 ; returns 1 (service is stopped) - returns 0 (service is not stopped)
| |
|
| |
| ; Show the error message if a function fails
| |
| SimpleSC::StopService "MyService" 1 30
| |
| Pop $0 ; returns an errorcode (<>0) otherwise success (0)
| |
| IntCmp $0 0 Done +1 +1
| |
| Push $0
| |
| SimpleSC::GetErrorMessage
| |
| Pop $0
| |
| MessageBox MB_OK|MB_ICONSTOP "Stopping fails - Reason: $0"
| |
| Done:
| |
| </highlight-nsis> | | </highlight-nsis> |
|
| |
|
| == Changelog ==
| | The complete function reference with all parameters and examples is available in the [https://github.com/Speed7811/nsis-simple-service-plugin#readme README on GitHub]. |
| * Version 1.30 (2011-08-15)
| |
| **SimpleSC::RemoveService doesn't stop the service now.
| |
| **SimpleSC::StartService, SimpleSC::StopService, SimpleSC::PauseService, SimpleSC::ContinueService and SimpleSC::RestartService got a new "Timeout" parameter. It is recommend to use a timeout of 30.
| |
| * Version 1.29 (2011-04-16)
| |
| **SimpleSC::GetServiceFailureFlag added
| |
| **SimpleSC::SetServiceFailureFlag added
| |
| **SimpleSC::GetServiceDelayedAutoStartInfo added
| |
| **SimpleSC::SetServiceDelayedAutoStartInfo added
| |
| * Version 1.28 (2010-09-14)
| |
| **SimpleSC::GetServiceFailure function added
| |
| **SimpleSC::SetServiceFailure function added
| |
| **SimpleSC::StopService WaitForFileRelease feature added (For details take a look at the documentation)
| |
| * Version 1.27 (2010-03-23)
| |
| **Documentation updated
| |
| * Version 1.26 (2009-05-21)
| |
| **Fixed wait for status bug on starting, stopping, pausing or continuing a service
| |
| * Version 1.25 (2009-04-23)
| |
| **SimpleSC::SetServiceLogon supports now non-domain username without the ".\"-prefix
| |
| **SimpleSC::SetServiceBinaryPath function added
| |
| *Version 1.24 (2009-04-13)
| |
| **Fixed wait for status bug if the service status changed. Now, if a service stops, starts aso. the plugin will work like the recommendations in the MSDN.
| |
| *Version 1.23 (2008-08-23)
| |
| **Removed compiler optimization to avoid a false-positive virusscan.
| |
| *Version 1.22 (2008-08-17)
| |
| **SimpleSC::GrantServiceLogonPrivilege and SimpleSC::RemoveServiceLogonPrivilege works now correct with domain names like MyDomain\MyUser.
| |
| **Added function SimpleSC::GetServiceLogon to get the logon username of a service.
| |
| *Version 1.21 (2008-02-10)
| |
| **SimpleSC::ExistsService results now 0 if the service exists and <> 0 if the service doensn´t exists.
| |
| *Version 1.20 (2008-02-05)
| |
| **Every function now returns <> 0 if there is an error. Use SimpleSC::GetErrorMessage to get the message of a function result.
| |
| **Added function SimpleSC::GetErrorMessage to get the message of a function result.
| |
| **SimpleSC::ExistsService results now 0 if the service exists and <> 0 if the service doensn´t exists.
| |
| **SimpleSC::RestartService supports now arguments.
| |
| ***'''Note''': The signature has been changed. If you update from a previous version you must check your parameters.
| |
| *Version 1.10 (2008-01-29)
| |
| **SimpleSC::InstallService supports now more than one dependencies (delimitter is the forward slash).
| |
| ***'''Note''': The signature has been changed. If you update from a previous version you must check your parameters.
| |
| **SimpleSC::InstallService supports now more service types e.g. to create an interactive service.
| |
| ***'''Note''': The signature has been changed. If you update from a previous version you must check your parameters.
| |
| **SimpleSC::StartService supports now arguments.
| |
| ***'''Note''': The signature has been changed. If you update from a previous version you must check your parameters.
| |
| *Version 1.05 (2008-01-12)
| |
| **The functions SimpleSC::StopService and SimpleSC::RestartService are now improved. Now all dependent services are stopping recursively too.
| |
| *Version 1.04 (2007-08-07)
| |
| **Fixed bug for possible endless loops. This concerns to the functions StartService, StopService, ContinueService and PauseService.
| |
| *Version 1.03 (2007-08-02)
| |
| **Added function SimpleSC::GetServiceBinaryPath to get the binary path of a specified service.
| |
| *Version 1.02 (2007-05-29)
| |
| **Changed wrong documentation informations about the functions SimpleSC::InstallService and SimpleSC::RemoveService.
| |
| *Version 1.01 (2007-05-07)
| |
| **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.
| |
| *Version 1.0 (2007-05-02)
| |
| **First offical version
| |
| | |
| == Important Notes ==
| |
| * Error codes are any non-zero value. For instance, if you attempt to start, stop, or query a service that does not exist, you may get the error code 1060.
| |
| *The function "SetServiceLogon" only works if the servicetype is "SERVICE_WIN32_OWN_PROCESS".
| |
| * The functions "GetServiceDescription" or "SetServiceDescription" are only available on systems higher than Windows NT.
| |
| * The function "GetServiceFailureFlag", "SetServiceFailureFlag", "GetServiceDelayedAutoStartInfo" and "SetServiceDelayedAutoStartInfo" are only available on systems higher than Windows 2003.
| |
| * 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.
| |
| * 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.
| |
| * If you have any suggestions, comments or questions please mail me: mailto:rainer@speed-soft.de
| |
|
| |
|
| [[Category:Plugins]] | | == Questions and bug reports == |
| | Please use the [https://github.com/Speed7811/nsis-simple-service-plugin/issues issue tracker on GitHub]. |