Check if java process is running with VB script

Option Explicit
Dim objWMIService, objProcess, colProcess, StdOut
Dim strComputer, strProcess, strCommand

strComputer = "." ' local computer
strProcess = "javaw.exe"
strCommand = "BatchReportingClient.jar"

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

' Function to check if a process is running
FUNCTION isProcessRunning(BYVAL strComputer,BYVAL strProcessName, BYVAL strCommand)

 DIM objWMIService, strWMIQuery

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


 IF objWMIService.ExecQuery(strWMIQuery).Count > 0 THEN
  isProcessRunning = TRUE
  Set colProcess = objWMIService.ExecQuery(strWMIQuery)
  'For Each objProcess in colProcess
  ' WSCript.Echo objProcess.CommandLine 
  'Next
 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