Winamp & Shoutcast Forums NSIS Simple Service Plugin

3rd May 2007, 17:51   #1
Speed78
Senior Member

Join Date: Jul 2003
Location: Germany
Posts: 109
NSIS Simple Service Plugin

Hi,

IÂ´ve create a service plugin. 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.

Here the function list:

Quote:
 SimpleSC::Install [name_of_service] [display_name] [start_type] [service_commandline] [dependencies] [account] [password] SimpleSC::Remove [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::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]
Here is the link to the wiki: http://nsis.sourceforge.net/NSIS_Simple_Service_Plugin

Any comments, suggestions and questions are welcome...

Best regards

Rainer

7th May 2007, 13:09   #2
Nicolas Cuny
Junior Member

Join Date: Oct 2003
Location: France
Posts: 15
Hi,

I just tested your plugin and was surprised to see that it doesn't need admin privileges to check the status of a service, contrary to the other available plugins. This was tested on Vista and XP Pro SP2.

This is very useful to me and I would like to know if this behaviour is intended and maybe a little explanation too

These are the scripts I used to double-check :

code:Name "simpleservice-test"
Outfile "simpleservice-test.exe"
ShowInstDetails show
RequestExecutionLevel user

Section -Main SEC0000
SetAutoClose false
SimpleSC::GetServiceStatus "W32Time"
pop $0 pop$1
DetailPrint $0 DetailPrint$1
SectionEnd

code:Name "nsscm-test"
Outfile "nsscm-test.exe"
ShowInstDetails show
RequestExecutionLevel user

Section -Main SEC0000
SetAutoClose false
nsSCM::QueryStatus "W32Time"
Pop $0 Pop$1
DetailPrint $0 DetailPrint$1
SectionEnd

code:!include "servicelib.nsh"

Name "servicelib-test"
Outfile "servicelib-test.exe"
ShowInstDetails show
RequestExecutionLevel user

Section -Main SEC0000
SetAutoClose false
!insertmacro SERVICE "status" "W32Time" ""
pop $0 DetailPrint$0
SectionEnd

And these are the results :

Quote:
 * simpleservice-test: 0 4 * nsscm-test: error 1 * servicelib-test: false
Thanks for the great job !

 7th May 2007, 16:37 #3 Nicolas Cuny Junior Member     Join Date: Oct 2003 Location: France Posts: 15 I found out so far that : - GetServiceStatus works with admin and user privileges - ExistsService only works with admin privileges - ServiceIsRunning works with both privileges, but documentation on the wiki is wrong : '1' means the service is running This has been tested on Vista and XP.
7th May 2007, 17:36   #4
Speed78
Senior Member

Join Date: Jul 2003
Location: Germany
Posts: 109
Hi,

Quote:
 Originally posted by Nicolas Cuny I found out so far that : - ExistsService only works with admin privileges - ServiceIsRunning works with both privileges, but documentation on the wiki is wrong : '1' means the service is running This has been tested on Vista and XP.
IÂ´ve changed the access flags for each functions so every function will be executed with the lowest privilege which is necessary. So I think ExistsService should now work with user privileges. A new version (1.01) of this plugin is available now.

IÂ´ve changed the wrong Result-Description for the functions ServiceIsRunning, ServiceIsPaused and ServiceIsStopped.

Any comments, suggestions and questions are welcome...

Best regards

Rainer

 24th May 2007, 09:05 #5 psmika Junior Member   Join Date: May 2007 Posts: 2 Hello, I'm am currently building an installer for a service application and I am using this plugin to create the service itself. I am able to create the service but in the service control manager there is no description. Also when the service starts a message is logged in the even viewer and then it says Service1 has been started even tho my service is called something else. Most likely im doing something wrong, it would be nice if someone could point me in the right direction. I have used the following command to add the service: SimpleSC::InstallService "MyService" "My Service" "2" "$INSTDIR\bin\MyService.exe" "" "" "" Thanks in advance for any help with this! // Mika 24th May 2007, 16:34 #6 Speed78 Senior Member Join Date: Jul 2003 Location: Germany Posts: 109 Hi, Quote:  I am able to create the service but in the service control manager there is no description. Thats correct. If you install the service the service description is not set. Please use the function "SetServiceDescription" to set a seperate description. Quote:  Also when the service starts a message is logged in the even viewer and then it says Service1 has been started even tho my service is called something else. I think Service1 is your Display name, otherwise you canÂ´t see it in eventlog. But I think your Key-Name (It is called [name_of_service] in plugin doc) is always the same. DonÂ´t confuse Display-Name and Key-Name. The Display-Name is a unique name you can see in the service controller at the column "Name". The Key-Name is a unique name you can see if you show the properties of a service. Best regards Rainer  25th May 2007, 08:04 #7 psmika Junior Member Join Date: May 2007 Posts: 2 Thank you so much for your response. The SetServiceDescription function works like a charm! I found out that the Service1 issue is a programming issue and it has nothing to do with this plugin. Thank you for the fast response and for this plugin!  29th May 2007, 16:02 #8 Andy1988 Junior Member Join Date: May 2007 Posts: 4 I tried to use your dll. I copied it into the Plugins folder in the folder where NSIS is installed, but the compiler always says that "SimpleSC::Install" is an illegal command. Do I need to define somewhere in my NSIS Script that I want to use your dll? I was not able to find anything about this in the Wiki, this forum or with google. Perhaps I'm blind Thank you for your help! 29th May 2007, 18:54 #9 Speed78 Senior Member Join Date: Jul 2003 Location: Germany Posts: 109 Hello Andy, Quote:  Originally posted by Andy1988 I tried to use your dll. I copied it into the Plugins folder in the folder where NSIS is installed, but the compiler always says that "SimpleSC::Install" is an illegal command. Do I need to define somewhere in my NSIS Script that I want to use your dll? I was not able to find anything about this in the Wiki, this forum or with google. Perhaps I'm blind A good message to you: You are not blind . That was my mistake. The documentation (in the readme.txt and on the wiki) was wrong about the name of the install and remove function. Only in the example it was correct. The function names are: • SimpleSC::InstallService SimpleSC::RemoveService IÂ´ve fixed it in the file and on the wiki. Best regards Rainer 29th May 2007, 22:27 #10 Andy1988 Junior Member Join Date: May 2007 Posts: 4 Quote:  Originally posted by Speed78 Hello Andy, A good message to you: You are not blind . That was my mistake. The documentation (in the readme.txt and on the wiki) was wrong about the name of the install and remove function. Only in the example it was correct. The function names are: SimpleSC::InstallService SimpleSC::RemoveService IÂ´ve fixed it in the file and on the wiki. Best regards Rainer It's great to hear that there is nothing wrong with my eyes Now everything works like expected! BTW: Great plugin! And thank you for your work and fast help!  26th July 2007, 19:42 #11 mr.hanky Junior Member Join Date: Feb 2006 Posts: 2 Request I think this is the best service plugin so far. I do have one request. An option that will show the config info. Like the qc option does for SC.exe in windows qc--------------Queries the configuration information for a service. The option I am looking for the most is to read BINARY_PATH_NAME Thanks again for the great plugin Chris  26th July 2007, 22:55 #12 Speed78 Senior Member Join Date: Jul 2003 Location: Germany Posts: 109 Hello Chris, I will add a function like "GetServicePath" in the next release. I think I will release it next days. Best regards Rainer  31st July 2007, 18:31 #13 lushdog Junior Member Join Date: Jul 2007 Posts: 37 When I do a SimpleSC::RemoveService yet the service is still in the Services list. If I try to restart the service I get a "The specified service has been marked for deletion." The service is removed from the list upon the next reboot. The only reason I ask is I'd like to let the user uninstall/reinstall without rebooting. I believe the "sc delete" command removes the service without a reboot. Does your plugin use "sc" or some other command? Thanks in advance, Matt 1st August 2007, 12:51 #14 Speed78 Senior Member Join Date: Jul 2003 Location: Germany Posts: 109 Hi lushdog, Quote:  Originally posted by lushdog When I do a SimpleSC::RemoveService yet the service is still in the Services list. If I try to restart the service I get a "The specified service has been marked for deletion." The service is removed from the list upon the next reboot. The only reason I ask is I'd like to let the user uninstall/reinstall without rebooting. I believe the "sc delete" command removes the service without a reboot. Does your plugin use "sc" or some other command? Thanks in advance, Matt The plugin uses the windows api functions. I think you have removed the service during your service list windows was opened!? If the service list is opened this is a default behaviour. Try to close the service list window and remove the service and then open the service list. You will see that the service is removed. "sc" uses the same functions like my plugin so "sc" has the same behaviour. Please remember: You should stop the service before you removing it. Best Regards Rainer  2nd August 2007, 19:08 #15 Speed78 Senior Member Join Date: Jul 2003 Location: Germany Posts: 109 New Version 1.03 Hi, IÂ´ve released a new version of the NSIS Simple Service Plugin. The new version provides the function "SimpleSC::GetServiceBinaryPath" to get the binary path of a specified service. You can find more informations and download file on the wiki page (http://nsis.sourceforge.net/NSIS_Simple_Service_Plugin). If you have any questions please let me now. Best regards Rainer  7th August 2007, 15:37 #16 Speed78 Senior Member Join Date: Jul 2003 Location: Germany Posts: 109 New Version 1.04 Hi, IÂ´ve released a new version of the NSIS Simple Service Plugin. This is an bugfix release that concerns to the functions StartService, StopService, ContinueService and PauseService. It is recommend to use this version of the plugin because it is possible that using this functions ends in an endless loop. This happens for example if the service doesnÂ´t start, stop aso. or e.g. the service crashes during startup (Function: StartService). You can find more informations and download file on the wiki page (http://nsis.sourceforge.net/NSIS_Simple_Service_Plugin). If you have any questions please let me now. Best regards Rainer  9th January 2008, 21:36 #17 jpderuiter Major Dude Join Date: Feb 2007 Posts: 672 Hello Rainer, this is a great plugin. I have a request: Could you add an option to SimpleSC::StopService to stop dependant services first? (Like the DOS command "net stop {ServiceName} /y".) Have a look at http://support.microsoft.com/kb/245230 for an idea. Thanks in advance, JP  10th January 2008, 06:44 #18 Speed78 Senior Member Join Date: Jul 2003 Location: Germany Posts: 109 Hello JP, I will add this feature in the next release. Best regards Rainer  12th January 2008, 15:51 #19 Speed78 Senior Member Join Date: Jul 2003 Location: Germany Posts: 109 New Version 1.05 Hi, IÂ´ve released a new version of the NSIS Simple Service Plugin. The functions SimpleSC::StopService and SimpleSC::RestartService are now improved. Now all dependent services are stopping recursively too. You can find more informations and download file on the wiki page (http://nsis.sourceforge.net/NSIS_Simple_Service_Plugin). If you have any questions please let me now. Best regards Rainer  13th January 2008, 10:43 #20 Afrow UK Moderator Join Date: Nov 2002 Location: Surrey, England Posts: 8,434 It would be very handy if you could add support for enabling desktop interaction when installing a service. This is ideal for Microsoft's srvany.exe executable which you can use to run any Windows executable as a service (silly enough though, the app that comes with it, instsrv.exe does not allow you to enable desktop interaction!) Stu  13th January 2008, 11:40 #21 Speed78 Senior Member Join Date: Jul 2003 Location: Germany Posts: 109 Hello Stu, I will add the feature in the next release. This feature will only run on systems older than Windows Vista. Vista doesnÂ´t support desktop interaction anymore (See: http://msdn2.microsoft.com/en-us/library/ms683502(VS.85).aspx) Best regards Rainer  13th January 2008, 12:03 #22 Afrow UK Moderator Join Date: Nov 2002 Location: Surrey, England Posts: 8,434 Righto thanks that's fine. Stu  14th January 2008, 22:38 #23 bradkohl Junior Member Join Date: Nov 2007 Location: San Jose, CA Posts: 12 Could you add the ability to start a service with a parameter? I tried adding my param to the end of the binary path and that didn't work. So far I like the plugin a lot, my only complaint is that it's a little bigger than other options like nsSCM and the ExistsService function seems to have odd return values compared to the other functions, the return value(1) seems more like a success case with that one, as opposed to the others which return (0) on success. Last edited by bradkohl; 15th January 2008 at 00:55.  15th January 2008, 11:49 #24 Afrow UK Moderator Join Date: Nov 2002 Location: Surrey, England Posts: 8,434 Try with a binary path as "path\to\app.exe" params Stu 16th January 2008, 10:50 #25 Speed78 Senior Member Join Date: Jul 2003 Location: Germany Posts: 109 Quote:  Originally posted by bradkohl Could you add the ability to start a service with a parameter? I tried adding my param to the end of the binary path and that didn't work. What exactly did you mean? If you mean the "InstallService" function then you can use your parameter in the "[service_commandline]" parameter. For example: SimpleSC::InstallService "MyService" "My Service Display Name" "2" "C:\MyPath\MyService.exe /process=server" "" "" "" Pop$0 ; return error(1)/success(0)

If you mean a start parameter in the "StartService" function then you are right. At the moment it is not implemented yet. If you need this please let me now and I will add this functionality.

Quote:
 [i] So far I like the plugin a lot, my only complaint is that it's a little bigger than other options like nsSCM [/B]
I think this is not really a problem. This plugin provides more functions and the harddisk are very cheap.

Quote:
 [i] The ExistsService function seems to have odd return values compared to the other functions, the return value(1) seems more like a success case with that one, as opposed to the others which return (0) on success. [/B]
Yes, you are right. The reason for this is that the function returns "True" or "False" - "True" is 1 and "False" is 0. I think its ok because itÂ´s documented in the wiki.

Best regards

Rainer

 18th January 2008, 16:56 #26 bradkohl Junior Member   Join Date: Nov 2007 Location: San Jose, CA Posts: 12 thanks for the reply, you're right the added functionality and flexibility does make up for the size, and yes I was talking about service 'start' parameters. It would be great if you could add them but in the mean time, I've hardcoded the param I needed in the source.
 18th January 2008, 18:21 #27 Speed78 Senior Member   Join Date: Jul 2003 Location: Germany Posts: 109 Hi bradkohl, I will add this functionality in the next release. Best Regards Rainer
 29th January 2008, 21:40 #28 Speed78 Senior Member   Join Date: Jul 2003 Location: Germany Posts: 109 New Version 1.10 Hi, IÂ´ve released a new version of the NSIS Simple Service Plugin. The changes are: - SimpleSC::InstallService supports now more than one dependencies (delimitter is the forward slash). - SimpleSC::InstallService supports now more service types e.g. to create an interactive service. - SimpleSC::StartService supports now arguments. Note: The signature of the functions SimpleSC::InstallService and SimpleSC::StartService has been changed. If you update from a previous version you must check your parameters. You can find more informations and download file on the wiki page (http://nsis.sourceforge.net/NSIS_Simple_Service_Plugin). If you have any questions please let me now. Best regards Rainer
 29th January 2008, 22:41 #29 pcrowley Junior Member   Join Date: Jan 2008 Posts: 6 One request I tried using this and got a consistent failure on creating a service. I need to create a kernel driver service which is a little different - the type is 1 rather than 16. Unfortunately, there doesn't seem to be a good way to get at the error returned. I might have been able to do a call with System to do a GetLastError, or maybe not. It would be very helpful to be able to get the reason for a failure. Even a new function like SimpleSC::GetError would be helpful.
 29th January 2008, 22:52 #30 Anders Moderator     Join Date: Jun 2002 Location: ${NSISDIR} Posts: 5,165 calling GetLastError with system.dll will not work, you will get the wrong result IntOp$PostCount $PostCount + 1 30th January 2008, 08:14 #31 Speed78 Senior Member Join Date: Jul 2003 Location: Germany Posts: 109 Re: One request Hi, Quote:  Even a new function like SimpleSC::GetError would be helpful. I think this function is helpful. I will add this in the next release. Did you installed your service successfully now? Best Regards Rainer  5th February 2008, 18:46 #32 Speed78 Senior Member Join Date: Jul 2003 Location: Germany Posts: 109 New Version 1.20 Hi, IÂ´ve released a new version of the NSIS Simple Service Plugin. The changes are: - 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 of the function SimpleSC::RestartService has been changed. If you update from a previous version you must check your parameters. You can find more informations and download file on the wiki page (http://nsis.sourceforge.net/NSIS_Simple_Service_Plugin). If you have any questions please let me now. Best regards Rainer  9th February 2008, 16:56 #33 Afrow UK Moderator Join Date: Nov 2002 Location: Surrey, England Posts: 8,434 I'm using the latest dll and SimpleSC::ExistsService is returning 0 when the service doesn't exist. Stu  9th February 2008, 20:07 #34 Afrow UK Moderator Join Date: Nov 2002 Location: Surrey, England Posts: 8,434 Also RemoveService appears to be returning a value other than 0 on success rather than on failure. Edit: My bad on RemoveService. The other function still returns 1 when it exists though. Stu  10th February 2008, 11:57 #35 Speed78 Senior Member Join Date: Jul 2003 Location: Germany Posts: 109 New Version 1.21 Hi, IÂ´ve released a new version of the NSIS Simple Service Plugin. The changes are: - SimpleSC::ExistsService results now 0 if the service exists and <> 0 if the service doensnÂ´t exists You can find more informations and download file on the wiki page (http://nsis.sourceforge.net/NSIS_Simple_Service_Plugin). Thanks to Stu for reporting this bug. If you have any questions please let me now. Best regards Rainer  10th February 2008, 12:03 #36 Afrow UK Moderator Join Date: Nov 2002 Location: Surrey, England Posts: 8,434 Thank you! Stu  4th July 2008, 09:30 #37 elllit Junior Member Join Date: Jun 2008 Location: Germany Posts: 18 Hi, in my installer I want to stop and delete an already running service, install the data and then install and start it again. Everything is fine, until it comes to the stopping/deleting point. It passes without error but the process stays active for another ~20s (on my system), causing the installer to show a message that the file, that is about to be installed, is currently in use. The service actually does not exist anymore. So checking for existance does not work. Sleeping for a static 30sec is not satisfying at all. Using the nsProcess plug-in to see wether my service is still running or not might be a solution (will try it next). But I hope that there is a better out there. Any suggestions? -- Till  4th July 2008, 12:31 #38 elllit Junior Member Join Date: Jun 2008 Location: Germany Posts: 18 Edit: Solved - Layer 8 issue *bangs the forehead on teh table* --- Oh, there is another issue: Installing for the standard user works flawlessly. But giving an account name and password it fails with error code 1057 that is: "Account invalid or does not exist" or something... I triple checked the strings and even hardcoded them into the script w/o success. :-( Im trying to install on a 2003 Server if that might help. Thanks, -- Till Last edited by elllit; 4th July 2008 at 13:17. 5th July 2008, 11:03 #39 Speed78 Senior Member Join Date: Jul 2003 Location: Germany Posts: 109 Hello Till, Quote:  Everything is fine, until it comes to the stopping/deleting point. It passes without error but the process stays active for another ~20s (on my system), causing the installer to show a message that the file, that is about to be installed, is currently in use. The service actually does not exist anymore. So checking for existance does not work. If the service doesnÂ´t exists (Stopped & Uninstalled) the plugin has done his work. A question to figure out where the problem is: Please try to stop your service with the plugin (not to uninstall!). After that please open your process list and check for your service process. Please repeat the same steps with the service manager. Does the service process exists in the process list? Quote:  Sleeping for a static 30sec is not satisfying at all. Using the nsProcess plug-in to see wether my service is still running or not might be a solution (will try it next). But I hope that there is a better out there. This is really nonsatisfying! Best regards Rainer 22nd July 2008, 11:52 #40 elllit Junior Member Join Date: Jun 2008 Location: Germany Posts: 18 Hi, first: sorry for the delay in answering your reply. Quote:  Originally posted by Speed78 Hello Till, If the service doesnÂ´t exists (Stopped & Uninstalled) the plugin has done his work. A question to figure out where the problem is: Please try to stop your service with the plugin (not to uninstall!). After that please open your process list and check for your service process. Please repeat the same steps with the service manager. Does the service process exists in the process list? I actually did that, but somehow I did something that obviously has fixed the problem, because I never had that delay issue since then. Anyways... I now have a issue that seemed to work all the time but now giving me a hard time. This is the code i use to start a service code:${If} $S_StartNowInput ==${BST_CHECKED}
DetailPrint Starting service
LogEx::Write /NOUNLOAD ... starting
LogEx::Write /NOUNLOAD ... >>> arguments: 
SimpleSC::StartService "${s_name}" "" Pop$0
${If}$0 <> 0
#SimpleSC::GetErrorMessage
#Pop $0 LogEx::Write /NOUNLOAD ... [InstallService] ERROR:$0
DetailPrint Could not start service! - Reason: $0 Goto cancel${EndIf}

DetailPrint ... done
\${EndIf}


This fragment is, with some more pieces, enclosed in a macro. Before starting the service it is installed without any sign of error. When it comes to starting it runs into the 30sec timeout (i guess) and gives me "1053" as result. Which in words means: "The service did not respond to the start or control request in a timely fashion" or something similar.

I'm pretty confused because I couldn't track down the cause of this. I'm not that familiar with windows' service handling and thus not sure what to look for.

Till

Last edited by elllit; 22nd July 2008 at 12:12.

 Winamp & Shoutcast Forums NSIS Simple Service Plugin