Hi All,
Firstly I am aware that this has been posted and answered before so I apologise in advance - I know how annoying it is repeating yourself but I am stumped, I have read all the posts I could find but really could not figure out how to implement the solutions posted.
Also this is my first foray into AutoIt so maybe I am missing the obvious?
So my script at the moment is like this, essentially I restart the process every 10 minutes cause it bums out, relaunch and press some buttons (to set it up again).
But, it doesnt bum out every 10 minutes, sometimes it bums out after 5 minutes and other times it could run for 4 hours+ so my method isn't very good really.
When it does bum out, the process continues but CPU drops to less than 5% for the process.exe
So I would like to implement a check every 30 secs for current CPU and if its less than say 20% then pskill process.exe and loop to the beggining.
So googling and searching etc led me to this but I don't understand scripting too well:
I think I am lost at: where in this script do I put process.exe and also 20% CPU? I found 1 example where the $process had been changed to taskmgr, but I am not sure why this is not taskmgr.exe?
If someone could point me in the right direction I would be very grateful.
Thanks in advance.
Firstly I am aware that this has been posted and answered before so I apologise in advance - I know how annoying it is repeating yourself but I am stumped, I have read all the posts I could find but really could not figure out how to implement the solutions posted.
Also this is my first foray into AutoIt so maybe I am missing the obvious?
So my script at the moment is like this, essentially I restart the process every 10 minutes cause it bums out, relaunch and press some buttons (to set it up again).
While 1 Run("process.exe") WinWaitActive("Window Name") Send("{RIGHT}") Send("{RIGHT}") Sleep(2000) Send("{TAB}") Sleep(2000) Send("{SPACE}") Sleep(600000) Run("pskill process.exe") Sleep(5000) WEnd
But, it doesnt bum out every 10 minutes, sometimes it bums out after 5 minutes and other times it could run for 4 hours+ so my method isn't very good really.
When it does bum out, the process continues but CPU drops to less than 5% for the process.exe
So I would like to implement a check every 30 secs for current CPU and if its less than say 20% then pskill process.exe and loop to the beggining.
So googling and searching etc led me to this but I don't understand scripting too well:
$process = "scite" While 1 Sleep(10) $cpu_usage = _Get_CPU_Usage(@ComputerName, 5, $process); return usages if above the percent passed in If Not @error Then MsgBox(0, "CPU Usage of " & $process, $cpu_usage) ExitLoop EndIf WEnd Func _Get_CPU_Usage($strComputer, $percent = 5, $strProcess = "") $wbemFlagReturnImmediately = 0x10 $wbemFlagForwardOnly = 0x20 $colItems = "" If $strProcess <> "" Then $strProcess = " WHERE Name = '" & $strProcess & "'" $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2") $colItems = $objWMIService.ExecQuery ("SELECT * FROM Win32_PerfFormattedData_PerfProc_Process" & $strProcess, "WQL", _ $wbemFlagReturnImmediately + $wbemFlagForwardOnly) If IsObj($colItems) Then For $objItem In $colItems If Number($objItem.PercentProcessorTime) > Number($percent) Then Return $objItem.PercentProcessorTime Next EndIf SetError(1) Return "" EndFunc ;==>_Get_CPU_Usage
I think I am lost at: where in this script do I put process.exe and also 20% CPU? I found 1 example where the $process had been changed to taskmgr, but I am not sure why this is not taskmgr.exe?
If someone could point me in the right direction I would be very grateful.
Thanks in advance.