FastHelper Posted June 8, 2008 Share Posted June 8, 2008 i want to run this code: expandcollapse popup$array = ProcessList("AutoIt3.exe") $iPID = $array[1][1] $sProcess = $iPID ;PID number for test process name ;~ $sProcess = "Idle" ;Other test process names ;~ $sProcess = "_Total" ;funny one ;~ $sProcess = "ntvdm" ;DOS process ;~ $sProcess = "AutoIt3" ;do not assign .exe to process name While 1 $iProcessCPU = _ProcessGetCPU($sProcess, 300 ) $sTip = "Process " & $sProcess & " CPU: " & $iProcessCPU & "%" traytip("", $sTip ,1) ;~ sleep(1000) ;set your own sleep time for LOOP mode WEnd Func _ProcessGetCPU($strProcess = "Idle", $iSampleTime = 500, $sComputerName = @ComputerName) ;~ All Parameters are optional: ;~ - Idle process will be measured if first parameter is not set ;~ - 500 ms is default sample time ;~ - This computer will be measured by default ;~ Process could be string ("Name") or PID number (1234) ;~ When more processes are runing with identical name, then the last opened is measured (use PID for other) ;~ For NORMAL MODE(one time measuring): set Sample value to more than 0 ms ;~ ( average CPU usage will be measured during sleep time within function) ;~ For LOOP MODE (continuous measuring): set Sample value to 0 ms ;~ ( average CPU usage will be measured between two function calls ) ;~ Total CPU usage is: ( 100 - _ProcessGetCPU()) ;~ Success: Returns process CPU usage in percent ;~ (Sample times below 100ms may return inaccurate results) ;~ (First result in Loop Mode may be inaccurate, ;~ because first call in Loop Mode is only used to trigger counters) ;~ Failure: Returns -1 ( wrong process name or PID ) ;~ : Returns -2 ( WMI service not found or Computer not found) if $strProcess = "" then $strProcess = "Idle" if $iSampleTime = "" AND IsString($iSampleTime) then $iSampleTime = 500 if $sComputerName = "" then $sComputerName = @ComputerName if not IsDeclared("iP1") AND $iSampleTime = 0 then ;first time in loop mode $bFirstTimeInLoopMode = 1 else $bFirstTimeInLoopMode = 0 endif if not IsDeclared("iP1") then assign("iP1", 0, 2) ;forced global declaration first time assign("iT1", 0, 2) endif $objWMIService = ObjGet("winmgmts:\\" & $sComputerName & "\root\CIMV2") if @error then return -2 if number($strProcess) then $strProcess = " WHERE IDProcess = '" & $strProcess & "'" else $strProcess = " WHERE Name = '" & $strProcess & "'" endif if $iSampleTime OR $bFirstTimeInLoopMode = 1 then ;skip if Loop Mode, but not First time $colItems = $objWMIService.ExecQuery ("SELECT * FROM Win32_PerfRawData_PerfProc_Process" & $strProcess) For $objItem In $colItems $iT1 = $objItem.TimeStamp_Sys100NS $iP1 = $objItem.PercentProcessorTime next if $objItem = "" then return -1 ;process not found sleep($iSampleTime) endif $colItems = $objWMIService.ExecQuery ("SELECT * FROM Win32_PerfRawData_PerfProc_Process" & $strProcess) For $objItem In $colItems $iP2 = $objItem.PercentProcessorTime $iT2 = $objItem.TimeStamp_Sys100NS next if $objItem = "" then return -1 ;process not found $iPP = ($iP2 - $iP1) $iTT = ($iT2 - $iT1) if $iTT = 0 Then return 100 ;do not divide by 0 $iCPU = round( ($iPP/$iTT) * 100, 0) $iP1 = $iP2 $iT1 = $iT2 Return $iCPU EndFunc ;==>_ProcessGetCPU() by novaTek ...ver 0.11 but got this error: Line -1: Error: Array variable has incorrect number of subscripts or subscript dimension range exceeded. please tell me what is wrong in it. sorry for my spelling mistakes. its due to be fast !!! Link to comment Share on other sites More sharing options...
Eigensheep Posted June 8, 2008 Share Posted June 8, 2008 I don't seem to get any errors at all, and it seems like a handly little script. However, the error specifies too large (or small) a subscript for the array variable. As you only seem to have one such variable ($array) accessed only in the line $array[1][1] which is totally valid, I can only come to the conclusion that the process "AutoIt3.exe" does not exist in your case. Try checking @error and $array[0][0] after the command and see what they return. Link to comment Share on other sites More sharing options...
BAM5 Posted June 8, 2008 Share Posted June 8, 2008 Well if you are compiling a program (I assume since the line is -1) the process is not named AutoIt3.exe. The process is the name of the compiled exe file. So if you want to test just take the exe that you compiled and rename it to AutoIt3.exe. Your script should work then. Array variable has incorrect number of subscripts or subscript dimension range exceeded. You get this error because it does not return any processes at all because no AutoIt3.exe process exists. Once again because the process name of your compiled program is the file name. So if I ran a program of mine called "Calculator.exe" the process would be called "Calculator.exe". [center]JSON Encoding UDF[/center] Link to comment Share on other sites More sharing options...
FastHelper Posted June 8, 2008 Author Share Posted June 8, 2008 can i add getting ram usage percentage information in this? sorry for my spelling mistakes. its due to be fast !!! Link to comment Share on other sites More sharing options...
BAM5 Posted June 8, 2008 Share Posted June 8, 2008 (edited) Heh, I really don't understand what you just said. Basically all you'd have to do is change the process name "AutoIt3.exe" to whatever your finished exe is going to be "ProcessInfo.exe", then name your compiled file "ProcessInfo.exe". Did it fix your problem? Edited June 8, 2008 by bam5 [center]JSON Encoding UDF[/center] Link to comment Share on other sites More sharing options...
FastHelper Posted June 8, 2008 Author Share Posted June 8, 2008 @ bam5 ya problem solved thanks sorry for my spelling mistakes. its due to be fast !!! Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now