pgg1
17th June 2008 12:00 UTC
Starting and stopping services
Hi
I want to be able to start/stop a service in windows. The service is a phone service that I have installed myself.
The problem I am having is that the service does not start or stop using the following snippet of code.
Starting:
ReadEnvStr $0 COMSPEC
nsExec::Exec '$0 net start PhoneService'
Pop $0
MessageBox MB_OK "$0"
Stopping;
nsExec::Exec '$0 net stop PhoneService'
Pop $0
MessageBox MB_OK "$0"
The installation of the service went ok because you can see it in the services table, where it's set to auto. Hence, the need to stop/start.
Any ideas?
Cheers
pgg1
17th June 2008 13:06 UTC
Concrete Example
This example should stop/start the windows service w32time (e.g. Windows Time).
outFile "installer.exe"
installDir $DESKTOP
section
setOutPath $INSTDIR
writeUninstaller $INSTDIR\uninstaller.exe
sectionEnd
section "Stop Windows Time Properties."
ReadEnvStr $0 COMSPEC
nsExec::Exec '$0 net stop w32time'
MessageBox MB_OK '$0 net stop w32time'
Pop $0
MessageBox MB_OK "$0"
sectionEnd
section "uninstall"
delete $INSTDIR\uninstaller.exe
# Start Windows Time Properties.
ReadEnvStr $0 COMSPEC
nsExec::Exec '$0 net start w32time'
MessageBox MB_OK '$0 net start w32time'
Pop $0
MessageBox MB_OK "$0"
sectionEnd
However, the above code does not stop or start the service. What am I doing wrong?
Can somebody please help me.
Thanks.
{_trueparuex^}
17th June 2008 13:54 UTC
I recommend using one of the service plug-ins to stop or start services. :)
http://nsis.sourceforge.net/How_do_I...heck_a_service
Yathosho
17th June 2008 16:21 UTC
i wasn't aware the necessity of using ReadEnvStr. i use just this command and had no problems so far. does the user have permission to stop services maybe?
nsExec::Exec 'net.exe STOP "wscsvc"'
pgg1
19th June 2008 15:35 UTC
Thanks guys.
Afrow UK
19th June 2008 16:13 UTC
I would use the SimpleSC plug-in and remove the dependency on net.exe to function.
Stu