1

I would like to kill Java processes running under all users except the process running as the SYSTEM user. As of now I'm using below code to kill process but it's terminating SYSTEM process as well.

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
  & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

Set colProcessList = objWMIService.ExecQuery _
  ("Select Name from Win32_Process WHERE Name LIKE 'java%'")

If colProcessList.Count > 0 Then
  For Each objProcess In colProcessList 
    objProcess.Terminate() 
  Next
End If

Set objWMIService = Nothing
Set colProcessList = Nothing
Ansgar Wiechers
  • 193,178
  • 25
  • 254
  • 328

0 Answers0