Option Explicit ' Variable Declaration Const ForReading = 1 Const ForWriting = 2 Dim objArgs, mode Dim objFSO, objReadFile, objWriteFile, strLog, strServerName, intCounthpboid, intCounthpbpro Dim objWMIService, colProcessList1, colProcessList2, objProcess ' Check Input Parameters On Error Resume Next strLog = "Scripting Running From: " & Now() & vbcrlf Set objArgs = WScript.Arguments mode = objArgs(0) ' Mode can be "Test", "Kill", or "" If mode = "" Then mode ="Test" WScript.Echo "Please note this script is running under " & mode & " mode, no action will be taken." Else WScript.Echo "Please note this script is running under " & mode & " mode, HPBOID.exe and HPBPRO.exe will be terminated." End If ' Create Object Set objFSO = CreateObject("Scripting.FileSystemObject") ' Open working files Set objReadFile = objFSO.OpenTextFile("C:\ServerList.txt", ForReading) Set objWriteFile = objFSO.CreateTextFile("C:\KillProcess.log", True) ' Looping Server List to check the process Do Until objReadFile.AtEndOfStream strServerName = objReadFile.Readline intCounthpboid = 0 intCounthpbpro=0 wscript.echo "" Wscript.echo strServerName Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" & strServerName & "\root\cimv2") Set colProcessList1 = objWMIService.ExecQuery _ ("Select * from Win32_Process Where Name = 'HPBOID.exe'") intCounthpboid = colProcessList1.count If intCounthpboid > 1 Then strLog = strLog & "Server Name: " & strServerName & vbcrlf If mode = "Kill" Then For Each objProcess in colProcessList1 objProcess.Terminate() Next End If strLog = strLog & intCounthpboid & " HPBOID.exe were terminated." & vbcrlf End If Set colProcessList2 = objWMIService.ExecQuery _ ("Select * from Win32_Process Where Name = 'HPBPRO.exe'") intCounthpbpro = colProcessList2.count If intCounthpbpro > 1 Then 'strLog = strLog & "Server Name: " & strServerName & vbcrlf If mode = "Kill" Then For Each objProcess in colProcessList2 objProcess.Terminate() Next End If strLog = strLog & intCounthpbpro & " HPBOID.exe were terminated." & vbcrlf End If colProcessList1.close colProcessList2.close objWMIService.close Loop strLog = strLog & "Ending at: " & Now() objWriteFile.WriteLine(strLog) objReadFile.Close objWriteFile.Close objFSO.Close set objFSO = nothing