Archive: NSIS Simple Service Plugin


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:

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

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 :

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


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


!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 :

* simpleservice-test:
0
4

* nsscm-test:
error
1

* servicelib-test:
false
Thanks for the great job !

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.


Hi,

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

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


Hi,

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.

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

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!


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!


Hello Andy,

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:

I´ve fixed it in the file and on the wiki.

Best regards

Rainer

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!

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


Hello Chris,

I will add a function like "GetServicePath" in the next release. I think I will release it next days.

Best regards

Rainer


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


Hi lushdog,

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

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


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


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


Hello JP,

I will add this feature in the next release.

Best regards

Rainer


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


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


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


Righto thanks that's fine.

Stu


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.


Try with a binary path as `"path\to\app.exe" params`

Stu


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.

[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.

[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

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.


Hi bradkohl,

I will add this functionality in the next release.

Best Regards

Rainer


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


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.


calling GetLastError with system.dll will not work, you will get the wrong result


Re: One request
Hi,

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

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


I'm using the latest dll and SimpleSC::ExistsService is returning 0 when the service doesn't exist.

Stu


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


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


Thank you!

Stu


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


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


Hello Till,

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?



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

Hi,

first: sorry for the delay in answering your reply.

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. :confused:

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


${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.

Any ideas? Thanks in advance.

Till

Archive: NSIS Simple Service Plugin


This to me would suggest a problem with the service itself. I personally have had no problems with SimpleSC installing, starting, stopping or uninstalling services.

I have seen that kind of error in a service that does not start the main thread in its start method.

Stu


Hello Till,

please try this script:

----------------------
Name "test"
OutFile "test.exe"

!Define SERVICE "TapiSrv"

Section
MessageBox MB_OK "NOTE: Result '0' means it was success otherwise '1'"

MessageBox MB_OK "Starting Service: ${SERVICE}"
SimpleSC::StartService "${SERVICE}" ""
Pop $0
MessageBox MB_OK "Result: $0"

SectionEnd
----------------------

This script will start the tapi service (In german: "Telefonie"... I don´t know the name in english :( )

I tested this script without any problems. If you also have no problems with this script I think the problem is your service. Can you check this and please give me a feedback!?

Best regards

Rainer


Speed78,

thanks for helping me.

The result your skript gives me is "1056".

The service "Telefonie" is running on my system and I can't stop it apperently (Error "1053" again). When I try to stop it via the services control list it says it needs to stop "RAS-Verbindungsverwaltung" which has "Telefonie" as a dependency. This is where the error comes into place. I guess it is used in the background somehow(?).

I'll talk with guys who code the service to check if the problem is on that side, following Afrow UK's suggestion which I also considered as another spot to search for a solution. But trying to find the error on oneself is the first way to go, isn't it? ;)

Till


Update:

I manged to get one service running with the help of a developer. The problem was that a dependency wasn given for the service, which I didn't know about.

Anyways, installing the other service mine is depending on solved the problem.

I hope its as "easy" with the other service. I will ask the colleague on monday and report about it.

I apology for bothering you as it was a fault on my side ;)


How can i get the LOGON NAME in a service

we have

SimpleSC::SetServiceLogon [name_of_service] [account] [password]

but i want something like this

GetServiceLogon (or something)

can ai get it ?


Hi,

the next day I will released a new version of the plugin. I will implement this function in the new version.

Best regards

Rainer


New Version 1.22
Hi,

I´ve released a new version of the NSIS Simple Service Plugin. The changes are:


- 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.


You can find more informations and download file on the wiki page (http://nsis.sourceforge.net/NSIS_Simple_Service_Plugin).

Thanks to everyone for reporting bugs and requesting features. If you have any questions please let me now.

Best regards

Rainer


Hi Speed78,

this version of SimpleSC was detected as a TROJAN when i used it in my compilation script

With version 1.21 there is no problem (but also there is no new functions)

without a antivirus , the new functions works right.

i'm using "Avast" in my computer.

could you review this version 1.22?

thank you


Hi,

I´ve checked the file and here the results.


http://www.virustotal.com/en/analisi...4b4943e04615dd

I´ve contacted AntiVir and Webwasher. AntiVir gave me the answer that the file is a FALSE-POSITIVE File and that they will modify the virus definitions. Webwasher gave me no answer at the moment.

I´m really confused about this because I only change some lines in the code and the scanner found a "pseudo"-virus.

I couldn´t determine some problems with "Avast". So you can take a look to the VirusTotal-URL.

Best regards

Rainer


New Version 1.23
Hi,

I´ve released a new version of the NSIS Simple Service Plugin. I detected that the compiler optimazation results in a false-positive virusscan, so I´ve removed it a I hope the problem is solved now.

You can find more informations and download file on the wiki page (http://nsis.sourceforge.net/NSIS_Simple_Service_Plugin).

Thanks to everyone for reporting bugs and requesting features. If you have any questions please let me now.

Best regards

Rainer


Now it works fine!!

thank you!


I have a service that takes some time to stop. How can I stop the service and wait until it is really stopped?


Hello,

take a look at the documentation: http://nsis.sourceforge.net/NSIS_Simple_Service_Plugin

The "SimpleSC::StopService"-Function is what you are searching for.

Kind regards

Rainer


New Version 1.24
Hi,

I´ve released a new version of the NSIS Simple Service Plugin. The changes are:


- 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. On some systems (especially 64Bit systems) the plugin returns "Stopped" although the service was not really stopped.

It is recommend to update your version of this plugin. 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


Setting only the binary path
I've been using version 1.24 of SimpleSC and I really appreciate it's ease of use. I'm currently working on a issue where the a service has been previously installed and now I'm trying to update only the binary path if it happened to be installed in a different location without changing the other settings associated with the service. Is there a SetServiceBinaryPath or some other way of performing this action.

Thanks

Allan McLellan


Hello Allan,

unfortunately, there is no possiblity to change the binary path. At the moment I recommend the following procedure:

1. Deinstall the service old "RemoveService"
2. Install the new service with the new binary path "InstallService".

Nethertheless, I will add the method "SetServiceBinaryPath" in the next version of this plugin, but this will take some weeks.

Kind regards

Rainer


Hi

Thanks for getting back to me so quickly. I'm currently checking to see if the new binary path equals the old binary path and if they don't then pop up a message box requiring the user to manually go in and change it via the service manager. It's not the nicest, but it doesn't really happen all that often. Again thanks for the quick response.

Allan


Hello Allan,

I think to compare the binary path of the old service with the new service is a good idea. But if the paths are not equal I think it´s more comfortable just to remove the old service (Take a look at SimpleSC::RemoveService) and install it again (Take a look at SimpleSC::InstallService). I think this should work. At the moment there is not possiblity to change the binary path in the service manager directly (AFAIK until Windows 2003). So the only way to change it is via command line "sc.exe".

Kind regards

Rainer


Originally posted by elllit


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
Hi Till,

We ran into the same problem. Turns out Windows wants the account name to be preceded by ".\". We figured this out by having Windows report the account owning the service. This works on XP, we're hopeful it will hold for other Windows platforms.

Just to be safe, we started the service as admin, then set service logon to the desired account.

The code that worked looks like this:

SimpleSC::InstallService "MyService" "My Service Display Name" "272" "2" "C:\MyPath\MyService.exe" "" "" ""

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:


Rainer, thanks for the great tool. Really saved our butts with this particular bug!

Saill

Hi Saill,

if I understand you correctly your problem with SetServiceLogon is ".\"-prefix of a non domain-account? I will check this for the next plugin-version.

Kind regards,

Rainer


Hi Rainer,

Exactly. My experiments show that any for any [account] input you need to add the ".\" prefix. Once you do that, it works great.

No real need to fix it - a note in the documentation should do the trick.

Thanks a lot for the tool. We used it to make sure that our service was owned by the current user so we could kill our runtime cleanly at shutdown. Solved one of our trickiest Windows bugs!

Warm regards,

Saill


Hello Saill,

I changed it in the online documentation but addionally I will change this in the next version.

Kind regards

Rainer


Hi Rainer,

That's great! I believe the .\ prefix is also necessary in the "account" input for:

SimpleSC::InstallSevice
SimpleSC::GrantServiceLogonPrivilege
SimpleSC::RemoveServiceLogonPrivilege

Warm regards,

Saill


1053 Error while starting the service
Hi,

I am trying to install a bat file as service.
I am able to create the service, but i am not able to start the service via script.
When i try to start the service manually i get the following windows error message.

"1053 service did not respond to the start or control request in a timely fashion"

Can anyone help me to fix this?

Thanks in advance,
Sadeesh


You can't use a batch file as a service. Not every program can be used as a service. It must be specifically designed for this purpose. There are some helpers that can turn any application to a service. Google "turn any application to a service" or something similar and you should be able to find them.


Batch file as service
I found a solution in order to use a Batch file as service. I used Flash Mx to create an EXE file that contains a FSCommand opening the Batch file. At last, the batch file is working as service.

I hope it works for you.

But I have another question:

I have a service running (not a batch file, of course). What's the best way to "interact" with the service? I have the service running but I can't find the way to open my application and change some config parameters, for example.

Can you help me with this issue?

I'm sorry for my english. I hope you can understand me.

Best wishes from Spain.


v1.24 - WZCSVC problem
Version 1.24 has a problem (at least on my system) with stopping the Wireless Zero Configuration.
SimpleSC::StopService "WZCSVC" does stop the service but is unaware of the status change and returns an error after the 30 s timeout ("The service did not respond to the start or control request in a timely fashion").
I tried several other windows services and there was no such problem. Version 1.23 deals with WZCSVC successfully. My system is XP SP2 but Wireless Zero Configuration has been updated (hotfix KB917021).


New Version 1.25
Hi,

I´ve released a new version of the NSIS Simple Service Plugin. The changes are:

- SimpleSC::SetServiceLogon supports now non-domain username without the ".\"-prefix
- SimpleSC::SetServiceBinaryPath function added

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.

Kind regards

Rainer


Re: v1.24 - WZCSVC problem
Hello,

Originally posted by aerDNA
Version 1.24 has a problem (at least on my system) with stopping the Wireless Zero Configuration.
SimpleSC::StopService "WZCSVC" does stop the service but is unaware of the status change and returns an error after the 30 s timeout ("The service did not respond to the start or control request in a timely fashion").
I tried several other windows services and there was no such problem. Version 1.23 deals with WZCSVC successfully. My system is XP SP2 but Wireless Zero Configuration has been updated (hotfix KB917021).
sry... I read this just now after releasing 1.25. I will check this on XP SP2 the next days. If you stop your service manually (via service control center) how much time takes it to stop the service (> 30 seconds) ?

Kind regards

Rainer

Re: Re: v1.24 - WZCSVC problem

Originally posted by Speed78
If you stop your service manually (via service control center) how much time takes it to stop the service (> 30 seconds) ?
When stopped manually, everything's ok (takes about 2 sec). With SimpleSC 1.23 it's also fine. The problem is with v1.24-1.25. Starting the service works ok in new versions, although it takes several seconds longer than with 1.23.

Hi Rainer,

What's the best way to "interact" with the service? I have the service running but I can't find the way to open my application and change some config parameters, for example.

Excuse me for my "stupid" question but I'm starting to use NSIS and I can't find a solution for this issue.

Thanks in advance.


Re: Re: Re: v1.24 - WZCSVC problem
Hi aerDNA,

Originally posted by aerDNA
When stopped manually, everything's ok (takes about 2 sec). With SimpleSC 1.23 it's also fine. The problem is with v1.24-1.25. Starting the service works ok in new versions, although it takes several seconds longer than with 1.23.
I´ve changed the code stop-service in version 1.24 because on some conditions the service doesn´t stop correctly. So please can you give me the following information:

Please try to stop the service via the plugin >= 1.24. Open during stopping the service the service control manager and take a look to the service at the "Status"-column. Which state do you see? "Stopping..."?

Did the service have dependencies?

Kind regards

Rainer

Hi pineapplex,

Originally posted by pineapplex
Hi Rainer,

What's the best way to "interact" with the service? I have the service running but I can't find the way to open my application and change some config parameters, for example.

Excuse me for my "stupid" question but I'm starting to use NSIS and I can't find a solution for this issue.

Thanks in advance.
there are several solutions to communicate with a service. You can use a TCP/IP socket, named pipes or shared memory. This depends on your knowledge about this methods and your service requirements.

Use this topics (TCP/IP socket, named pipes or shared memory) to get more addionally informations for you programming language.

Kind regards

Rainer

Re: Re: Re: Re: v1.24 - WZCSVC problem
Hi aerDNA,

Originally posted by Speed78
Hi aerDNA,



I´ve changed the code stop-service in version 1.24 because on some conditions the service doesn´t stop correctly. So please can you give me the following information:

Please try to stop the service via the plugin >= 1.24. Open during stopping the service the service control manager and take a look to the service at the "Status"-column. Which state do you see? "Stopping..."?

Did the service have dependencies?

Kind regards

Rainer
I can reproduce your behaviour now and I will fix asap.

Kind regards

Rainer

New Version 1.26
Hi,

I´ve released a new version of the NSIS Simple Service Plugin. The changes are:

- Fixed wait for status bug on starting, stopping, pausing or continuing a service

You can find more informations and download file on the wiki page (http://nsis.sourceforge.net/NSIS_Simple_Service_Plugin).

Thanks to aerDNA for reporting this bug. If you have any questions please let me now.

Kind regards

Rainer


Glad I could help. There are several service plugins but personally I prefer yours. I used it to make a little util aimed specifically at managing WZC / WLAN Autoconfig. Compiled with v1.26 and works like a charm. So thank you.


I tried using V1.26 to Set Logon account info for the Service and was not able to do it. When I visited your plugin page at http://nsis.sourceforge.net/NSIS_Simple_Service_Plugin and found there is a note: The function "SetServiceLogon" only works if the servicetype is "SERVICE_WIN32_OWN_PROCESS"

Would you please explain a little more about this servicetype? And how do I check and adjust the servicetype? Thanks a lot.


Hello kalix11,

Originally posted by kalix11
I tried using V1.26 to Set Logon account info for the Service and was not able to do it. When I visited your plugin page at http://nsis.sourceforge.net/NSIS_Simple_Service_Plugin and found there is a note: The function "SetServiceLogon" only works if the servicetype is "SERVICE_WIN32_OWN_PROCESS"
At the moment there is no possibility to get or set the service type. I would add these functions in the next version of the plugin.

If you create a service on your own you should know the service type.

Some useful link about the service type can be found here:

http://msdn.microsoft.com/en-us/library/ms681987(VS.85).aspx

See "lpServiceStartName [in, optional]" - lpServiceStartName is the username!

Kind regards

Rainer

Thank you for your reply. I checked my service using some 3rd party tool and found the servicetype is SERVICE_WIN32_OWN_PROCESS. Can you think of any reason why SetServiceLogon is not working? I tried username with ".\" or without ".\", all the same results. Or should I first grant LogonAsService privilege to the user account before I call SetServiceLogon?


Hi kalix11,

Originally posted by kalix11
Thank you for your reply. I checked my service using some 3rd party tool and found the servicetype is SERVICE_WIN32_OWN_PROCESS. Can you think of any reason why SetServiceLogon is not working? I tried username with ".\" or without ".\", all the same results. Or should I first grant LogonAsService privilege to the user account before I call SetServiceLogon?
You don´t need this "\."-prefix in version 1.26 and you don´t need grant service logon before SetServiceLogon.

Make sure that the user exists. If the user exists please please check the error result using the GetErrorMessage-Function like in this example:

SimpleSC::SetServiceLogon "MyService" "MyServiceUser" "MyServiceUserPassword"
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 "SetServiceLogon fails - Reason: $0"
Done:

Kind regards

Rainer

Archive: NSIS Simple Service Plugin


Thanks for the quick reply. I used your code and found out the reason is : The account name is invalid or does not exist, or the password is invalid for the account name specified.

However, I'm pretty sure I'm using an existing account and provided right password. I also create a test account and it still failed. Any thoughts on it?


Hi,

Originally posted by kalix11
Thanks for the quick reply. I used your code and found out the reason is : The account name is invalid or does not exist, or the password is invalid for the account name specified.

However, I'm pretty sure I'm using an existing account and provided right password. I also create a test account and it still failed. Any thoughts on it?
Can you give me the account name? Is this a domain account, then you have to use domain\user - syntax!? Does the name contains some specail characters? Remark: The plugin is not a unicode plugin!

Kind regards

Rainer

The test account is just called "test" with password the same. Nothing fancy, just a proof of concept.


Hi,

Originally posted by kalix11
The test account is just called "test" with password the same. Nothing fancy, just a proof of concept.
I can´t reproduce it. I have created on Windows Vista and Windows XP a local user called "test" with the same password and used the function without any problems!

So please can you give me the following informations:

1. Which NSIS Version do you use?
2. Which OS + SP + Language are you using?
3. Please can you post your NSIS setup lines here. If possible can you send me a sample setup to rainer@speed-soft.de

Kind regards

Rainer

Thank you so much for your time. I'll try to clean up other stuffs and give you only what it needs to reproduce the error and send you the email. Thanks again.

BTW, the service was created using a java service wrapper from http://wrapper.tanukisoftware.org/. I don't know whether this would make any difference.


Rainer is the MAN! Eventually there was an error in my code not passing the correct username and password. No wonder it would fail. There is nothing wrong with the plug-in.

Rainer rocks!!!


Originally posted by elllit
Hi,

first: sorry for the delay in answering your reply.



I actually did that, but somehow I did something that obviously has fixed the problem, because I never had that delay issue since then. :confused:

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


${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.

Any ideas? Thanks in advance.

Till
I understand that this post may be over a year old, but I was having the same issue. When installing my service it would throw a 1053 error when trying to start.

I found the solution was to register the service:

ExecWait '"$INSTDIR\${PRODUCT_NAME}\Product.exe" /service'


After doing this, SimpleSC::StartService worked just fine.

Hello,

Quote:


the problem of elllit was that there exists services which depends on his service. Because of that the service doesn´t start.

I think your problem was that your service wasn´t installed. Because of this your service doesn´t start. You can use your method which works of course or you can use the method SimpleSC::InstallService which is the general method for every service. However, you need to install the service first and after this you can start the service.

Kind regards

Rainer

Originally posted by disruptor108
I found the solution was to register the service:

ExecWait '"$INSTDIR\${PRODUCT_NAME}\Product.exe" /service'


After doing this, SimpleSC::StartService worked just fine.

Hi Rainer,

I m new to NSIS Script and I have been trying to install a Windows Service using your service plugin. I want to run a JAR file, rather than an exe, when the service starts.
The service gets installed but I m not able to get it started. Whenever the installed service is started an error pops up saying "Could not start MyService service on Local Computer. Error 193: 0xc1".
I know the fact that this error comes up if the application is not valid Win32 application but I dont find any issues with my attempt of installation.
Using NSIS script I m placing (installing) the required files into installation directory and using service plugin I install it where the <binary_path> value in SimpleSC::InstallService points to the JAR file placed in the installation directory.
Can you please guide me?

Thank You,
Janvi


I'd expect you would need to execute java with the jar as a parameter. Jar files aren't executable by themselves.


Hi MSG,

Thank you for replying. I tried what you said but it turned out to be a vain attempt. It's still not working. I guess the problem is not because of the JAR file.

I tried a different scenario to check if the JAR file is causing the problem. I tried to run notepad.exe as a service. This time a different error message popped up saying "Error 1053: The service didn't respond in timely fashion."

I have kept the script as simple as possible so that it remains less error prone.
Following is the script; please guide me if you find anything wrong:

<Script>

Name "TestService"
OutFile "TestService.exe"

InstallDir '$PROGRAMFILES\TestService'

SetCompress Auto
SetDateSave On
SetDataBlockOptimize On
SetOverwrite on

Section
SetOutPath $INSTDIR
File 'F:\Projects\JavaService.jar'
File 'F:\Projects\notepad.exe'

# SimpleSC::InstallService [name_of_service] [display_name] [service_type] [start_type]
# [binary_path] [dependencies] [account] [password]

SimpleSC::InstallService "TestService" "TestService" "16" "2"\
"$INSTDIR\JavaService.jar" "" "" ""
Pop $0 ; returns an errorcode (<>0) otherwise success (0)
detailprint $0

# Start service
SimpleSC::StartService "TestService"
Pop $0 ; returns an errorcode (<>0) otherwise success (0)
detailprint $0

</Script>

I dont understand what's wrong. Please help..

Thank You,
Janvi


Hi,

Just some update.. I converted my JAR file into an exe using Jar2Exe tool. Now, using the same script I m able to run this exe as Windows Service. Any clue??

Thank You,
Janvi


Hi..
Can anyone please guide me to solve the problem i'm facing?
Any help will be greatly appreciated.

Thank You,
Janvi


Since a service has to communicate with the OS (like "I'm still running"), I think it's not possible to install a jar file as service.

See the following for more info / what you can try:

http://edn.embarcadero.com/article/32068
http://www.coderanch.com/t/429680/Ge...jar-as-Windows


I has another issue with SimpleSC.dll. I installed the Unicode NSIS, then SimpleSC::ServiceIsRunning always return the service status is stopped (0) no matter my service is running or not.

Speed78, is there Unicode SimpleSC plug-in available? So urgent need this.


As far as I know SimpleSC is not available in Unicode.

As a workaround to find if a service is running you can use:

   !include "WordFunc.nsh"
Var Service
.
.
.
; inside function / section
StrCpy $Service "ServiceName"

Push "ExecDos::End" # Add a marker for the loop to test for.
ExecDos::exec /TIMEOUT=2000 /TOSTACK 'sc.exe query "$Service"' "" ""
Pop $0 # return value
StrCmp $0 0 0 NotRunning
## Loop through stack.
StrCpy $2 0
Loop:
Pop $1
StrCmp $1 "ExecDos::End" ExitLoop
${WordFind} "$1" "RUNNING" "*" $3
Intcmp $3 0 NotFound NotFound
IntOp $2 $2 + 1
NotFound:
StrCpy $3 "0"
Goto Loop
ExitLoop:
IntCmp $2 0 NotRunning NotRunning Running
NotRunning:
DetailPrint "$Service is not running"
Goto End
Running:
DetailPrint "$Service is running"
Goto End
End:
Hope this helps.
(The ExecDos plugin is available for unicode:
http://forums.winamp.com/showthread.php?threadid=181442)

Thanks for help.
But ExceDos (Unicode version)cannot find the running windows service as well... no clue what wrong with it
:eek:


OK.

Well, I didn't test this in Unicode, but what's the output of ExecDos?
(Add DetailPrint "$1" after Pop $1 in the loop to see what it is)


Problem after deleting and then Install a service
Hello together,

I have following problem with the simplesc plugin.
I install my service with installutil of .net, because when I try to install with simplesc, then the services will hnot start, I think this is because that the dependencies are not correct updated.
Anyway, when I install my service with installutil, update then the logon with:
SimpleSC::SetServiceLogon "<name>" "$USER_NAME" "$USER_PASSWORD"

everything works fine.
Then I start my installer again and update my installation.
Within the "Function preuninstall_function" i stop the services if they are running with:
SimpleSC::StopService "<name>"
and then remove the service with:
SimpleSC::RemoveService "<name>" or again with
installutil of .net (makes no sense what I use, the service is removed from the list),

but when I now try to reinstall the service again in my Section like explained above,
the service is installed, but the user update will fail:
SimpleSC::SetServiceLogon "<name>" "$USER_NAME" "$USER_PASSWORD"

Any ideas?
Thanks,
Ebi70


Hello,

sry for this answer-delay. I don't get any message that somebody posts in this thread and I don't know why :(.


Originally posted by Ebi70
Hello together,

I have following problem with the simplesc plugin.
I install my service with installutil of .net, because when I try to install with simplesc, then the services will hnot start, I think this is because that the dependencies are not correct updated.
1. Please post the sc.exe command and the SimpleSC::InstallService command which you are using.
2. After using sc.exe and SimpleSC::InstallService, please check the dependencies in the Windows service manager.
3. Please post the dependencies of your service.





Originally posted by Ebi70
but when I now try to reinstall the service again in my Section like explained above,
the service is installed, but the user update will fail:
SimpleSC::SetServiceLogon "<name>" "$USER_NAME" "$USER_PASSWORD"
Please use the GetErrorMessage Function to get the error. In the documentation you can find an example how to use it.

Kind regards

Rainer

New Version 1.28
Hi,

I've released a new version of the NSIS Simple Service Plugin. There are two new functions SimpleSC::GetServiceFailure and SimpleSC::SetServiceFailure. The function SimpleSC::StopService has now an addional argument to wait for file release if you would overwrite the binary file.

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.

Special thanks to Rogier for this great donation. He makes this changes possible.

Best regards

Rainer


Hello, I'm having problems with this plugin, 1.28.

StrCpy$P_ServiceName"EcoManager_$P_ServiceID"

SimpleSC::ExistsService"$P_ServiceName"
Pop$0;returnsanerrorcodeiftheservicedoesn´texists(<>0)/serviceexists(0)
MessageBoxMB_OK"Servizio$P_ServiceNameesiste?$0"
Even though the service name is built correctly and it doesn't exists, the messagebox says $0 value is 0.

Maybe is it something about unicode (trying it on XP SP3)?

Thank you,
Mario

Dear mabian,

if your service name contains Unicode characters you will get problems. This version of the service plugin doesn't support Unicode.

1. Please enter SimpleSC::ExistsService your service name and don't use a variable (only for testing).
2. Try to use the ExistsService-Method with an other service. If this works I asume that it depends on your servicename + Unicode.
3. Please use the GetErrorMessage Method to get error text.

Please let me know your results.

Kind regards

Rainer


This fragment:

SimpleSC::ExistsService"Dnscache"

Pop$0;returnsanerrorcodeiftheservicedoesn´texists(<>0)/serviceexists(0)
MessageBoxMB_OK"$0"
Push$0
SimpleSC
::GetErrorMessage
Pop
$0
MessageBoxMB_OK
|MB_ICONSTOP"Message:$0"
Produces a few japanese chars in the first message box and a longer japanese/chinese string in the second...

- Mario

Same with an unexisting service name.

Thanks,
Mario

Dear mabian,

you can only use GetErrorMessage if an error exists e.g.

SimpleSC::ExistsService"Dnscache"

Pop$0;returnsanerrorcodeiftheservicedoesn´texists(<>0)/serviceexists(0)
MessageBoxMB_OK"$0"
IntCmp$00Done+1+1
Push
$0
SimpleSC
::GetErrorMessage
Pop
$0
MessageBoxMB_OK
|MB_ICONSTOP"Message:$0"

Done:
nethertheless this is not the problem. Are you using the Unicode-Version of NSIS? If yes please try it with the Non-Unicode. I just tried it with the Non-Unicode Version of NSIS and it works for me.

Kind regards

Rainer

Confirmed: the ANSI version of NSIS works as expected.

I thought the dll would work with Unicode NSIS as long as no unicode strings were used.

Thank you very much!

- Mario


Hi
Thanks for this plug-in. Now i am able to install/start/stop...of 'my service' through this.
but i am not able to see this in the 'services.msc'.
please let me know how to list this 'my service' into 'services.msc', so that later on i can stop/start/restart manually.

Thanks,
Rajanikanth


Dear Rajanikanth,

if you can install/start/stop the service your service should be displayed in the ServiceManager (services.msc) or I don't understand you correctly!?

Kind regards

Rainer


Rajanikanth,

if you have services.msc already open while the installer adds the service, you have to press F5 to make it update the service list.

Installing a service adds it to the list here.

- Mario


Hi, I have created a workaround to make it work with Unicode. You first need to enter this into your code:

PHP Code:


!defineUnicode2Ansi"!insertmacroUnicode2Ansi"

!macroUnicode2AnsiStringoutVar
System
::Call'kernel32::WideCharToMultiByte(i0,i0,w"${String}",i-1,t.s,i${NSIS_MAX_STRLEN},i0,i0)i'
Pop"${outVar}"
!macroend

And then you call SimpleSC functions like this:
PHP Code:
${Unicode2Ansi}"my_service_short_name"$R0
SimpleSC
::StopService"$R0"0
Pop
$0

It will obviously not work with chars, that are really Unicode (like Chinese) and probably also with everything non-english or non-local-language, but in standard situations, it should work. If there are any problems, let me know in this thread.

New Version 1.29
Hi,

I've released a new version of the NSIS Simple Service Plugin. There are four new functions:

- GetServiceFailureFlag
- SetServiceFailureFlag
- GetServiceDelayedAutoStartInfo
- SetServiceDelayedAutoStartInfo

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


SimpleSC checks whether the service is stopped before calling DeleteService. This is fine in normal circumstances, but some services cannot be stopped (they have no handler). I'd rather SimpleSC just went ahead and called DeleteService anyway, where in such cases the service will be deleted on reboot (i.e. DeleteService returns 1072). If you don't want to change the current behaviour, at least add a /force switch or something which ignores the state of the service.

Stu


Hey Stu,

I think the best way is to do it like windows does it in the "sc delete" command. Therefore I will remove the "Stopped"-check in the code. I will change it within the next week.

Kind regards

Rainer


[wait_for_file_release]
Hi Rainer,

Originally posted by Speed78
I've released a new version of the NSIS Simple Service Plugin. There are two new functions SimpleSC::GetServiceFailure and SimpleSC::SetServiceFailure. The function SimpleSC::StopService has now an addional argument to wait for file release if you would overwrite the binary file.
As you said, I used SimpleSC::StopService with "wait_for_file_release" flag, since i need to overwrite the binary file.

Sometimes our services take longer time,>30sec, to stop in that case
SimpleSC::StopService "<My Service Name>" 1
Will return with an error# 1053 (The service did not respond to the start or control request in a timely fashion).


Currently I am over coming this using loop and check status logic. below is my code snippet



SimpleSC::StopService "<My Service Name>" 1
; My service take more than 30sec to stop sometimes since it is doing some file processing
Pop $0
;"1053 error (The service did not respond to the start or control request in a timely fashion)
Goto CheckServiceStateNoSleep
LoopAgain:
DetailPrint "Waiting for service to stop..."
Sleep 2000
CheckServiceStateNoSleep:
SimpleSC::GetServiceStatus "<My Service Name>"
Pop $0
Pop $1
IntCmp $1 1 ServiceStopped LoopAgain LoopAgain
ServiceStopped:
;Service Exe replacement step here


Is there any better alternatives?

Thank you,
Riju

Hi Riju,

if your service need more than 30 seconds I think you are using the registry setting ServicePipeTimeout!? Otherwise you should get a windows message e.g. if you are stopping the service via Service Manager.

So I can do the following:

1. I can wait until the service controller gave me the result information after an action (e.g. stopped, timeout, etc.). The disadvantage can be that I'm waiting forever and the setup seems to hang.

2. I can add a wait timeout parameter in the function. The disadvantage is that the timeout doesn't depend on the windows timeout.

However, I think I need to check it and I will try to change it within the next release. I have another task on my todo list for Stu, but at the moment my work in the company is very stressful. Therefore it can take a time.

Kind regards

Rainer


Hi Rainer,

I appreciate you for taking time from your busy schedule to reply our queries.. Thank you!!

Originally posted by Speed78

So I can do the following:

1. I can wait until the service controller gave me the result information after an action (e.g. stopped, timeout, etc.). The disadvantage can be that I'm waiting forever and the setup seems to hang.

2. I can add a wait timeout parameter in the function. The disadvantage is that the timeout doesn't depend on the windows timeout.
I think, wait timeout parameter in the function will do the trick. If timeout is 0, it will wait till the service stop properly.

I see it rather an advantage than a disadvantage, In a sense you are providing an optional parameter to override the default windows timeout. That is always an advantage :)

Thank you very much,
Riju

@ZvyaginzevaE:
Googled what you're looking for and seems it can be obtained easily. But you completely missed the forum, this one has nothing to do with cars.


NSIS 1.30 Beta
Dear all,

in the attachment you can find a Beta version of the new NSIS plugin. This version contains these new functions:

The following functions got a new "Timeout" parameter:

  • SimpleSC::StartService
  • SimpleSC::StopService
  • SimpleSC::PauseService
  • SimpleSC::ContinueService
  • SimpleSC::RestartService

The function SimpleSC::RemoveService doesn't stop the service now. If you need this functions please use the SimpleSC::StopService before you remove the service.

It would be great if you can check this new version. Any feedback will be welcome.

Kind regards

Rainer

New Version 1.30
Dear all,

no news are good news. Therefore I released a new version of the NSIS Simple Service Plugin.

There are four new functions:

  • The function SimpleSC::RemoveService doesn't stop the service now. If you need this functions please use the SimpleSC::StopService before you remove the service.
  • The following functions got a new "Timeout" parameter:
    • SimpleSC::StartService
    • SimpleSC::StopService
    • SimpleSC::PauseService
    • SimpleSC::ContinueService
    • SimpleSC::RestartService

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

Hi Rainer,

I really appreciate you for coming up with "timeout parameter" as requested. However I am sorry, currently I am away from the installer project; hoping to back soon too. I will definitely do my aprt of testing and let you know my experience.

btw, is there any infinite timeout value like "-1" or "0"?

Thank you,
Riju


Archive: NSIS Simple Service Plugin


Can I use this plugin in for commercial use of my installer:confused:?


By default all plug-ins can be used in commercial installers.
If it is not strictly prohibited in plug-in readme then feel free to use it.


Hello! My problem. Services plug-in not work! Help please!Service does not start!


!define PRODUCT_NAME "MyApp"
!define PRODUCT_VERSION "19"
!define pkgdir "C:\Swe"

!include "MUI.nsh"
SetCompressor /SOLID lzma

!define MUI_ABORTWARNING
!insertmacro MUI_PAGE_FINISH
!insertmacro MUI_LANGUAGE "Russian"

Name "${PRODUCT_NAME}"
Caption "Установка ${PRODUCT_NAME} ${PRODUCT_VERSION}"
OutFile "${PRODUCT_NAME}-${PRODUCT_VERSION}.exe"
ShowInstDetails show

Section
SetOutPath "C:\"

File "${pkgdir}\SystemTrayDemo.exe"

SimpleSC::InstallService "ServiceStartD" "Testing123D" "16" "2" "C:\SystemTrayDemo.exe" "" "" ""
SimpleSC::StartService "ServiceStartD" "" 30
SectionEnd

Can you start it if you run services.msc (Computer management)?


Originally posted by dixonich
Hello! My problem. Services plug-in not work! Help please!Service does not start!

!define PRODUCT_NAME "MyApp"
!define PRODUCT_VERSION "19"
!define pkgdir "C:\Swe"

!include "MUI.nsh"
SetCompressor /SOLID lzma

!define MUI_ABORTWARNING
!insertmacro MUI_PAGE_FINISH
!insertmacro MUI_LANGUAGE "Russian"

Name "${PRODUCT_NAME}"
Caption "Установка ${PRODUCT_NAME} ${PRODUCT_VERSION}"
OutFile "${PRODUCT_NAME}-${PRODUCT_VERSION}.exe"
ShowInstDetails show

Section
SetOutPath "C:\"

File "${pkgdir}\SystemTrayDemo.exe"

SimpleSC::InstallService "ServiceStartD" "Testing123D" "16" "2" "C:\SystemTrayDemo.exe" "" "" ""
SimpleSC::StartService "ServiceStartD" "" 30
SectionEnd
Which error mesage do you got (GetErrorMessage)? Are you using the unicode version of NSIS?

Kind regards

Rainer

Hi,Speed78
Nice to meet you.I have a problem when use NSIS Simple Service Plugin to install a windows service named "Apache".
When i use "SimpleSC::InstallService ...." ,the service is installed ok,but it can not start,the error is "required components not installed".
I have a try to use "apache/bin/httpd -k install",i saw the dependences are "AFD",and "TCP/IP Protocal Driver / IPSEC driver".
So,how can i use simplesc to install this apache ?

By the way,StartSercie,StopService need 30 seconds,that's so long! My production need to install 4 service on user's computer,so that's need too much time! Can you tell me if the SimpleSC can do this like "sc start httpd","sc stop httpd" ?

Best Regards
From your chinese friend :)


When i use "SimpleSC::InstallService ...." ,the service is installed ok,but it can not start,the error is "required components not installed".
I have a try to use "apache/bin/httpd -k install",i saw the dependences are "AFD",and "TCP/IP Protocal Driver / IPSEC driver".
So,how can i use simplesc to install this apache ?
Use "AFD/IPSec/Tcpip" as dependencies in the InstallService command (see http://nsis.sourceforge.net/NSIS_Simple_Service_Plugin)

Thank you very much

Originally posted by jpderuiter
Use "AFD/IPSec/Tcpip" as dependencies in the InstallService command (see http://nsis.sourceforge.net/NSIS_Simple_Service_Plugin)
To jpderuiter,
thank you very much!

I have a try what you said,the dependences are installed successfully! thanks again!
But tha apache software can not start yet.i don't know why,i think the software has its own process when use "-k install".but i still thanks you told me how to use the dependence parameter:)

Another question,do you know how to install a .NET service except using "installutil.exe" ?
I have a .exe that developed by .net framework 4.0,i try to use SimpleSC to install ,and i failed,i must to use the .NET install tool "installutil.exe" to install it.

Ah,do you understand what i said ? :) ,i am sorry about my english.

but,all of these are ok! i have write a .exe instead of that one.

Thanks again!

i have to improve my english now ,today i met a German teacher,thanks to God,there is a senior student there ,and she can speak german very well~:)

You only need to use installutil.exe if the .NET service uses the ServiceInstaller/ServiceProcessInstaller classes to define its install configuration. If you just create the service and only extend the ServiceBase class then you can install it using the normal Windows APIs (i.e. SimpleSC will work).

Stu