reddredson
asked on
Tasklisk and taskkill bats
Hello,
I have a software that multiple users on a terminal server use and I am trying to create a bat file to kill a specific process when becomes non responsive. Here is the scenario. At any given time i could have 40+ users logged in all using a process [wrun32.exe] but it sometimes it will hang at 25% processor utilization. Needless to say if four users have processes the server is locked up. I created the following script to find the hung process and send its process ID as a variable that i can use taskkill to close.
::Kill WRUN ON SERVER01
:SERVER01
for /f "usebackq tokens=2" %%a in (`tasklist /s SERVER01 /FO list /FI "IMAGENAME eq wrun32.exe" /FI "STATUS eq NOT RESPONDING" ^| find /i "PID:"`) do set PID=%%a
IF %PID%=NUL GOTO END Else taskkill /F /S SERVER01 /pid %PID%
:END
cls
I need to find a way to get this to only run on a process that is hung with the CPU utilization at 25% and run every 5 minutes. Any suggestions?
I have a software that multiple users on a terminal server use and I am trying to create a bat file to kill a specific process when becomes non responsive. Here is the scenario. At any given time i could have 40+ users logged in all using a process [wrun32.exe] but it sometimes it will hang at 25% processor utilization. Needless to say if four users have processes the server is locked up. I created the following script to find the hung process and send its process ID as a variable that i can use taskkill to close.
::Kill WRUN ON SERVER01
:SERVER01
for /f "usebackq tokens=2" %%a in (`tasklist /s SERVER01 /FO list /FI "IMAGENAME eq wrun32.exe" /FI "STATUS eq NOT RESPONDING" ^| find /i "PID:"`) do set PID=%%a
IF %PID%=NUL GOTO END Else taskkill /F /S SERVER01 /pid %PID%
:END
cls
I need to find a way to get this to only run on a process that is hung with the CPU utilization at 25% and run every 5 minutes. Any suggestions?
ASKER
I wish is was as simple as an antivirus problem but it is caused from a program our company uses called Persona written from AcuCOBOL-GT. From what i gather [ wrun32.exe *32 ] it functions to emulate the job of a multi-processor server so multiple users can share the use of it but I can only find instances where the issue occurs on quad-core processor machines.
Can the VBScript help you to find processes consuming the CPU?
ASKER
The script does show the running processes but i already know the process name. Its "wrun32.exe *32".
The script was just a sample, I've modified it to filter just for wrun32. Check what it will show for a hanging wrun32.exe
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
set objRefresher = CreateObject("WbemScripting.SWbemRefresher")
Set colItems = objRefresher.AddEnum _
(objWMIService, "Win32_PerfFormattedData_PerfProc_Process").objectSet
objRefresher.Refresh
Wscript.Echo Now
For Each objItem in colItems
if objItem.Name = "wrun32" then
objRefresher.Refresh
Wscript.Echo vbCrLf & "Name: " & objItem.Name
Wscript.Echo " Creating Process ID: " & objItem.CreatingProcessID
Wscript.Echo " Percent Processor Time: " & _
objItem.PercentProcessorTime
End if
Next
ASKER
It does show the process and current cpu load but it only will show one. I could have the same process running 40 times with the same name but only one of them will be hung at 25%. Once i find that process that is hung at 25% i need to kill it. The wrun32.exe will be running but never get over 5% but on rare occasions it will spike to 25% and hang.
Try this please. I wasn't aware that it the function will add #1, #2 and so on for each instance ...
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
set objRefresher = CreateObject("WbemScripting.SWbemRefresher")
Set colItems = objRefresher.AddEnum _
(objWMIService, "Win32_PerfFormattedData_PerfProc_Process").objectSet
objRefresher.Refresh
Wscript.Echo Now
For Each objItem in colItems
if Instr(objItem.name,"wrun32") > 0 then
objRefresher.Refresh
Wscript.Echo vbCrLf & "Name: " & objItem.Name
Wscript.Echo " Creating Process ID: " & objItem.CreatingProcessID
Wscript.Echo " Percent Processor Time: " & _
objItem.PercentProcessorTime
End if
Next
ASKER
Few questions:
1. The actual PID for the process is completely different. Where are these Process ID's coming from?
2. Not sure how this is supposed to help when i already know the process and the current PID. Is it a way to echo the process current process utilization? Maybe export it as a variable? Is this VB script only identifying the processes?
1. The actual PID for the process is completely different. Where are these Process ID's coming from?
2. Not sure how this is supposed to help when i already know the process and the current PID. Is it a way to echo the process current process utilization? Maybe export it as a variable? Is this VB script only identifying the processes?
1. Sorry, I didn't realize the script shows the PID of the creating process. Change line 14 to
Wscript.Echo " Process ID: " & objItem.IDProcess
and you get the correct PID.
2. I thought your problem is to determine the PID of the hanging process out of multiple processes with the same name. I was hoping the script will show ehich of the wrun32 processes consumes your cpu.
Next step would be to use the PID with the highest CPU to kill the process.
Wscript.Echo " Process ID: " & objItem.IDProcess
and you get the correct PID.
2. I thought your problem is to determine the PID of the hanging process out of multiple processes with the same name. I was hoping the script will show ehich of the wrun32 processes consumes your cpu.
Next step would be to use the PID with the highest CPU to kill the process.
ASKER
ok so here is what i came up with so far
========================== ========== ======
Dim vbShell
Dim var1
DIM var2
Dim batchFile
Set vbShell = CreateObject("WScript.Shel l")
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=imper sonate}!\\ " & strComputer & "\root\cimv2")
set objRefresher = CreateObject("WbemScriptin g.SWbemRef resher")
Set colItems = objRefresher.AddEnum _
(objWMIService, "Win32_PerfFormattedData_P erfProc_Pr ocess").ob jectSet
objRefresher.Refresh
Wscript.Echo Now
For Each objItem in colItems
if Instr(objItem.name,"wrun32 ") > 0 then
objRefresher.Refresh
Wscript.Echo vbCrLf & "Name: " & objItem.Name
Wscript.Echo " Process ID: " & objItem.IDProcess
Wscript.Echo " Percent Processor Time: " & _
objItem.PercentProcessorTi me
var1 = objItem.IDProcess
quotedVar1 = " " & """" & var1 & """"
var2 = objItem.PercentProcessorTi me
quotedVar2 = " " & """" & var2 & """"
batchFile = "C:\Users\Username\Desktop \batfile1. bat"
vbShell.run batchFile & quotedVar1 & quotedVar2
set vbShell=nothing
End if
Next
========================== ========== ========== ==
So it finds the process, gives me correct PID and process utilization and passes the values as variable to a batch file. Thank you so much so far. but is there a query i can have it check by. Something like:
Set colProcesses = objWMIService.ExecQuery("S ELECT * FROM Win32_Process") | where objItem.PercentProcessorTi me > 20
Whould that work ?
==========================
Dim vbShell
Dim var1
DIM var2
Dim batchFile
Set vbShell = CreateObject("WScript.Shel
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=imper
set objRefresher = CreateObject("WbemScriptin
Set colItems = objRefresher.AddEnum _
(objWMIService, "Win32_PerfFormattedData_P
objRefresher.Refresh
Wscript.Echo Now
For Each objItem in colItems
if Instr(objItem.name,"wrun32
objRefresher.Refresh
Wscript.Echo vbCrLf & "Name: " & objItem.Name
Wscript.Echo " Process ID: " & objItem.IDProcess
Wscript.Echo " Percent Processor Time: " & _
objItem.PercentProcessorTi
var1 = objItem.IDProcess
quotedVar1 = " " & """" & var1 & """"
var2 = objItem.PercentProcessorTi
quotedVar2 = " " & """" & var2 & """"
batchFile = "C:\Users\Username\Desktop
vbShell.run batchFile & quotedVar1 & quotedVar2
set vbShell=nothing
End if
Next
==========================
So it finds the process, gives me correct PID and process utilization and passes the values as variable to a batch file. Thank you so much so far. but is there a query i can have it check by. Something like:
Set colProcesses = objWMIService.ExecQuery("S
Whould that work ?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I figured out a simpler solution to my issue and wanted the answerd question availiable for others who may get the same problem.
Is this Acuserver?
Try http://www.symantec.com/connect/forums/acuserver-problem
Basically they are excluding every directory that has to do with the software from the antivirus program.
If this is not the solution, a VBScript could do that:
http://gallery.technet.microsoft.com/scriptcenter/49489911-f686-4a74-98f8-ed121fd7d544