cypher175 Posted May 17, 2009 Share Posted May 17, 2009 I was searching for some Code/UDF to give me the ( CPU% ) of a Specified Process/PID, and came across a few UDF's but most of them seem to use the WMI in their script..I came across this thread and saw this code that seems to get the total CPU of the System I thnk without using the WMI..http://www.autoitscript.com/forum/index.ph...mp;#entry269843So I was wondering if there would be anyway to get the CPU% of a Specified Process/PID somehow using the code below, I dont want to use the WMI in my script.. So would anything like this be possible at all..??expandcollapse popupFunc CurrentCPU($init = 0) Global $liOldIdleTime = 0 Global $liOldSystemTime = 0 Local $SYS_BASIC_INFO = 0 Local $SYS_PERFORMANCE_INFO = 2 Local $SYS_TIME_INFO = 3 $SYSTEM_BASIC_INFORMATION = DllStructCreate("int;uint;uint;uint;uint;uint;uint;ptr;ptr;uint;byte;byte;short") $status = DllCall("ntdll.dll", "int", "NtQuerySystemInformation", "int", $SYS_BASIC_INFO, _ "ptr", DllStructGetPtr($SYSTEM_BASIC_INFORMATION), _ "int", DllStructGetSize($SYSTEM_BASIC_INFORMATION), _ "int", 0) If $status[0]Then Return -1 While 1 $SYSTEM_PERFORMANCE_INFORMATION = DllStructCreate("int64;int[76]") $SYSTEM_TIME_INFORMATION = DllStructCreate("int64;int64;int64;uint;int") $status = DllCall("ntdll.dll", "int", "NtQuerySystemInformation", "int", $SYS_TIME_INFO, _ "ptr", DllStructGetPtr($SYSTEM_TIME_INFORMATION), _ "int", DllStructGetSize($SYSTEM_TIME_INFORMATION), _ "int", 0) If $status[0]Then Return -2 $status = DllCall("ntdll.dll", "int", "NtQuerySystemInformation", "int", $SYS_PERFORMANCE_INFO, _ "ptr", DllStructGetPtr($SYSTEM_PERFORMANCE_INFORMATION), _ "int", DllStructGetSize($SYSTEM_PERFORMANCE_INFORMATION), _ "int", 0) If $status[0]Then Return -3 If $init = 1 Or $liOldIdleTime = 0 Then $liOldIdleTime = DllStructGetData($SYSTEM_PERFORMANCE_INFORMATION, 1) $liOldSystemTime = DllStructGetData($SYSTEM_TIME_INFORMATION, 2) Sleep(1000) If $init = 1 Then Return -99 Else $dbIdleTime = DllStructGetData($SYSTEM_PERFORMANCE_INFORMATION, 1) - $liOldIdleTime $dbSystemTime = DllStructGetData($SYSTEM_TIME_INFORMATION, 2) - $liOldSystemTime $liOldIdleTime = DllStructGetData($SYSTEM_PERFORMANCE_INFORMATION, 1) $liOldSystemTime = DllStructGetData($SYSTEM_TIME_INFORMATION, 2) $dbIdleTime = $dbIdleTime / $dbSystemTime $dbIdleTime = 100.0 - $dbIdleTime * 100.0 / DllStructGetData($SYSTEM_BASIC_INFORMATION, 11) + 0.5 Return $dbIdleTime EndIf $SYSTEM_PERFORMANCE_INFORMATION = 0 $SYSTEM_TIME_INFORMATION = 0 WEnd EndFunc ;==>CurrentCPU Link to comment Share on other sites More sharing options...
BrettF Posted May 17, 2009 Share Posted May 17, 2009 Can I ask why no WMI? Vist my blog!UDFs: Opens The Default Mail Client | _LoginBox | Convert Reg to AU3 | BASS.au3 (BASS.dll) (Includes various BASS Libraries) | MultiLang.au3 (Multi-Language GUIs!)Example Scripts: Computer Info Telnet Server | "Secure" HTTP Server (Based on Manadar's Server)Software: AAMP- Advanced AutoIt Media Player | WorldCam | AYTU - Youtube Uploader Tutorials: Learning to Script with AutoIt V3Projects (Hardware + AutoIt): ArduinoUseful Links: AutoIt 1-2-3 | The AutoIt Downloads Section: | SciTE4AutoIt3 Full Version! Link to comment Share on other sites More sharing options...
cypher175 Posted May 17, 2009 Author Share Posted May 17, 2009 Just dont want to depend on a service to get me the info that I want.. unless there is no other possible way of getting it.. Is there anyway to get the CPU of a Specified Process/PID without using the WMI..?? Link to comment Share on other sites More sharing options...
ProgAndy Posted May 17, 2009 Share Posted May 17, 2009 I think, you have to work with Performance Counters, but this is difficult *GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes Link to comment Share on other sites More sharing options...
cypher175 Posted May 17, 2009 Author Share Posted May 17, 2009 so using MWI is pretty much the simplest way then..?? Can any of you please tell me what the above code I posted is getting..?? is the the total SYSTEM CPU% Usage or something else..?? Link to comment Share on other sites More sharing options...
ProgAndy Posted May 17, 2009 Share Posted May 17, 2009 The code in Post #1 returns the total CPU usage like the graph in teh Taskmanager. *GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes 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