This is more of a DOS question than a vbscript question, but it's for a vbscript app.
Is there a way to get only the STATE of a service rather than a list of all the statuses for a service, then get these into vbscript?
I haven't tried this code below, because it's doesn't seem acceptable to loop through the output until you find the word "RUNNING" in the output, but I may have to do something like this. So it's not a afunction yet.
It gives you and idea of what I'm doing.
This is the output that I would be working with, and the line that I specifically want to get is"
STATE : 4 RUNNING
I don't know how to get that, I know how to get the below:
DISPLAY_NAME: Simple Mail Transfer Protocol (SMTP)
TYPE : 20 WIN32_SHARE_PROCESS
STATE : 4 RUNNING
WIN32_EXIT_CODE : 0
SERVICE_EXIT_CODE : 0
CHECKPOINT : 0x0
WAIT_HINT : 0x0
' this is a subroutine, but could be a function that returns the SMPT status
' the DOS command will be to query the SMTPSVC status
' I could not figure out how to get the
strCommand = "CMD /C SC QUERY SMTPSVC"
intStyle = 10
intDOSError = 0
intSMTPStatus = 0
Dim fldTemp, strTempName
set fsoRun = CreateObject("Scripting.FileSystemObject")
Set fldTemp = fsoRun.GetSpecialFolder(TEMP_FOLDER)
strTempName = fldTemp.Path & "\" & fsoRun.GetTempName
Set WshShell = CreateObject("Wscript.Shell")
Return = WshShell.Run(strCommand & " >" & strTempName, intStyle, True )
'Get the output from the command
Set filOutput = fsoRun.OpenTextFile(strTempName, FOR_READING)
While Not filOutput.AtEndOfStream
strOutput = filOutput.ReadLine
' This is where I would like to get the SMTP status
If InStr(strOutput,"STATE") > 0 And InStr(strOutput,"RUNNING") > 0 Then
' If the status of SMPTSVC is running then flag it as 1
intSMPTStatus = 1
intDOSError = Return
'Delete the temporary file
Set WshShell = Nothing