Chekc if process is running with VB script

  

OPTION EXPLICIT
DIM strComputer,strProcess

strComputer = "." 
strProcess = "wrapper.exe"

' Check if Wrapper is running on specified computer
IF isProcessRunning(strComputer,strProcess) THEN
 wscript.echo strProcess & " is running on computer '" & strComputer & "'"
ELSE
 wscript.echo strProcess & " is NOT running on computer '" & strComputer & "'"
END IF


FUNCTION isProcessRunning(BYVAL strComputer,BYVAL strProcessName)

 DIM objWMIService, strWMIQuery

 strWMIQuery = "Select * from Win32_Process where name like '" & strProcessName & "'"
 
 SET objWMIService = GETOBJECT("winmgmts:" _
  & "{impersonationLevel=impersonate}!\\" _ 
   & strComputer & "\root\cimv2") 


 IF objWMIService.ExecQuery(strWMIQuery).Count > 0 THEN
  isProcessRunning = TRUE
 ELSE
  isProcessRunning = FALSE
 END IF

END FUNCTION

留言

這個網誌中的熱門文章

java.lang.NoClassDefFoundError: org/apache/xerces/jaxp/datatype/XMLGregorianCalendarImpl$Parser

10 Tips for Proper Application Logging

Turn off WebLogic basic authentication