Script to check the CCMExec service state

Have you ever needed to remotely check the state of the SMS Agent Host service, on a desktop or server?

Run the following VBScript, you'll be prompted for the computer name.

' save as CheckCCMExecSvc.vbs

dim strMsg
dim bFound
ON ERROR RESUME NEXT
ComputerName = InputBox("Enter the name of the computer for which you want service information")

winmgmt1 = "winmgmts:{impersonationLevel=impersonate}!//" & ComputerName & ""
If err.number <> 0 Then
Msgbox "Computer not found."
Wscript.quit  1
End If

Set ServSet = GetObject( winmgmt1 ).InstancesOf ("Win32_service")
If err.number <> 0 Then
Msgbox "Computer/services not found."
Wscript.quit  1
End If

bFound = False
strMsg = "Computer not found."
FOR EACH Serv in ServSet
    strMsg = ""
'   GetObject("winmgmts:").InstancesOf ("win32_service")
  IF Left(Serv.DisplayName, 3) = "SMS" Then
    bFound = True
'   WScript.Echo ""
'    strMsg = ""
    strMsg = strMsg & Serv.Description & vbCRLF
    strMsg = strMsg & " Executable: " & Serv.PathName & vbCRLF
    strMsg = strMsg & " Status: " & Serv.Status & vbCRLF
    strMsg = strMsg & " State: " & Serv.State & vbCRLF
    strMsg = strMsg & " Start Mode: " & Serv.StartMode & vbCRLF
    strMsg = strMsg & " Start Name: " & Serv.StartName & vbCRLF
    strMsg = strMsg & vbCRLF
  end if
NEXT
If bFound = False Then
   Msgbox "SMS agent not found!"
else
   msgbox strMsg
'    strMsg = ""
end if

Published Friday, February 13, 2009 11:17 AM by sthompson

Comments

No Comments
Powered by Community Server (Commercial Edition), by Telligent Systems