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

留言

這個網誌中的熱門文章

Disable ionic's sidemenu content drag to toggle menu

Multiple writable mappings exist for the field. Only one may be defined as writable, all others must be specified read-only.

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