Skip to content
⌘ NSIS Forum Archive

Starting and stopping services

6 posts

pgg1#

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#
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^}#
I recommend using one of the service plug-ins to stop or start services. 🙂

Yathosho#
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"'