If you can use plug-ins:
Using the Simple Service Plugin, you can do this:
SimpleSC::GetServiceStatus "MyService"
Pop $0 ; returns an errorcode (!=0) otherwise success (0)
Pop $1 ; return the status of the service (see below)
If successful, the service status will have one of the following numeric values:
- STOPPED
- START_PENDING
- STOP_PENDING
- RUNNING
- CONTINUE_PENDING
- PAUSE_PENDING
- PAUSED
If you can NOT use plug-ins:
Note that I added /C to FIND.exe to output the line count instead of the entire line. Also, be careful modifying the quotes. It took some trial and error to get that right.
StrCpy $R0 '"$SYSDIR\cmd.exe" /c "sc QUERY MyServiceName | FIND /C "RUNNING""'
nsExec::ExecToStack '$R0'
Pop $R1 # contains return code
Pop $R2 # contains output
${If} $R1 == "0"
# command success
${If} $R2 == "1"
# it's running
${Else}
# it's not running
${EndIf}
${Else}
# command failed
${EndIf}
Be sure to include the logic library, as NSIS requires this for conditional statement macros:
# Included files
!include LogicLib.nsh
t use plugins because i need to give this script to ohter people, that haven
t plugins at all – Ladner