DarkNecromancer Posted July 15, 2005 Share Posted July 15, 2005 Hay does anyone know of any dll that i can call that will return the cpu load? Link to comment Share on other sites More sharing options...
GaryFrost Posted July 15, 2005 Share Posted July 15, 2005 don't know of any easy to get load usage from a dll. here's an example using wmi and objects in beta (LoadPercentage is what your looking for I believe): expandcollapse popup; Generated by AutoIt Scriptomatic $wbemFlagReturnImmediately = 0x10 $wbemFlagForwardOnly = 0x20 $colItems = "" $strComputer = "localhost" $Output="" $Output = $Output & "Computer: " & $strComputer & @CRLF $Output = $Output & "==========================================" & @CRLF $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2") $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_Processor", "WQL", _ $wbemFlagReturnImmediately + $wbemFlagForwardOnly) If IsObj($colItems) then For $objItem In $colItems $Output = $Output & "AddressWidth: " & $objItem.AddressWidth & @CRLF $Output = $Output & "Architecture: " & $objItem.Architecture & @CRLF $Output = $Output & "Availability: " & $objItem.Availability & @CRLF $Output = $Output & "Caption: " & $objItem.Caption & @CRLF $Output = $Output & "ConfigManagerErrorCode: " & $objItem.ConfigManagerErrorCode & @CRLF $Output = $Output & "ConfigManagerUserConfig: " & $objItem.ConfigManagerUserConfig & @CRLF $Output = $Output & "CpuStatus: " & $objItem.CpuStatus & @CRLF $Output = $Output & "CreationClassName: " & $objItem.CreationClassName & @CRLF $Output = $Output & "CurrentClockSpeed: " & $objItem.CurrentClockSpeed & @CRLF $Output = $Output & "CurrentVoltage: " & $objItem.CurrentVoltage & @CRLF $Output = $Output & "DataWidth: " & $objItem.DataWidth & @CRLF $Output = $Output & "Description: " & $objItem.Description & @CRLF $Output = $Output & "DeviceID: " & $objItem.DeviceID & @CRLF $Output = $Output & "ErrorCleared: " & $objItem.ErrorCleared & @CRLF $Output = $Output & "ErrorDescription: " & $objItem.ErrorDescription & @CRLF $Output = $Output & "ExtClock: " & $objItem.ExtClock & @CRLF $Output = $Output & "Family: " & $objItem.Family & @CRLF $Output = $Output & "InstallDate: " & WMIDateStringToDate($objItem.InstallDate) & @CRLF $Output = $Output & "L2CacheSize: " & $objItem.L2CacheSize & @CRLF $Output = $Output & "L2CacheSpeed: " & $objItem.L2CacheSpeed & @CRLF $Output = $Output & "LastErrorCode: " & $objItem.LastErrorCode & @CRLF $Output = $Output & "Level: " & $objItem.Level & @CRLF $Output = $Output & "LoadPercentage: " & $objItem.LoadPercentage & @CRLF $Output = $Output & "Manufacturer: " & $objItem.Manufacturer & @CRLF $Output = $Output & "MaxClockSpeed: " & $objItem.MaxClockSpeed & @CRLF $Output = $Output & "Name: " & $objItem.Name & @CRLF $Output = $Output & "OtherFamilyDescription: " & $objItem.OtherFamilyDescription & @CRLF $Output = $Output & "PNPDeviceID: " & $objItem.PNPDeviceID & @CRLF $strPowerManagementCapabilities = $objItem.PowerManagementCapabilities(0) $Output = $Output & "PowerManagementCapabilities: " & $strPowerManagementCapabilities & @CRLF $Output = $Output & "PowerManagementSupported: " & $objItem.PowerManagementSupported & @CRLF $Output = $Output & "ProcessorId: " & $objItem.ProcessorId & @CRLF $Output = $Output & "ProcessorType: " & $objItem.ProcessorType & @CRLF $Output = $Output & "Revision: " & $objItem.Revision & @CRLF $Output = $Output & "Role: " & $objItem.Role & @CRLF $Output = $Output & "SocketDesignation: " & $objItem.SocketDesignation & @CRLF $Output = $Output & "Status: " & $objItem.Status & @CRLF $Output = $Output & "StatusInfo: " & $objItem.StatusInfo & @CRLF $Output = $Output & "Stepping: " & $objItem.Stepping & @CRLF $Output = $Output & "SystemCreationClassName: " & $objItem.SystemCreationClassName & @CRLF $Output = $Output & "SystemName: " & $objItem.SystemName & @CRLF $Output = $Output & "UniqueId: " & $objItem.UniqueId & @CRLF $Output = $Output & "UpgradeMethod: " & $objItem.UpgradeMethod & @CRLF $Output = $Output & "Version: " & $objItem.Version & @CRLF $Output = $Output & "VoltageCaps: " & $objItem.VoltageCaps & @CRLF if Msgbox(1,"WMI Output",$Output) = 2 then ExitLoop $Output="" Next Else Msgbox(0,"WMI Output","No WMI Objects Found for class: " & "Win32_Processor" ) Endif Func WMIDateStringToDate($dtmDate) Return (StringMid($dtmDate, 5, 2) & "/" & _ StringMid($dtmDate, 7, 2) & "/" & StringLeft($dtmDate, 4) _ & " " & StringMid($dtmDate, 9, 2) & ":" & StringMid($dtmDate, 11, 2) & ":" & StringMid($dtmDate,13, 2)) EndFunc SciTE for AutoItDirections for Submitting Standard UDFs Don't argue with an idiot; people watching may not be able to tell the difference. Link to comment Share on other sites More sharing options...
DarkNecromancer Posted July 15, 2005 Author Share Posted July 15, 2005 hmm... that works i suppose, but here is what i came up with:expandcollapse popup; Script generated by AutoBuilder 0.5 Prototype #include <GuiConstants.au3> HotKeySet("{f1}", "toggle") Global $loop = 1 $strComputer = "localhost" $wbemFlagReturnImmediately = 0x10 $wbemFlagForwardOnly = 0x20 If Not IsDeclared('WS_CLIPSIBLINGS') Then Global $WS_CLIPSIBLINGS = 0x04000000 GuiCreate("CPU/MEM Stat", 222, 117,(@DesktopWidth-222)/2, (@DesktopHeight-117)/2 , $WS_OVERLAPPEDWINDOW + $WS_VISIBLE + $WS_CLIPSIBLINGS) $Progress_1 = GuiCtrlCreateProgress(0, 0, 220, 10) $Label_1 = GuiCtrlCreateLabel("CPU Usage", 0, 10, 110, 20) $Label_2 = GuiCtrlCreateLabel("Physical Memory", 0, 40, 90, 20) $Progress_2 = GuiCtrlCreateProgress(0, 30, 220, 10) $Label_3 = GuiCtrlCreateLabel("Page File", 0, 70, 60, 20) $Progress_3 = GuiCtrlCreateProgress(0, 60, 220, 10) $Label_4 = GuiCtrlCreateLabel("Virtual Memory", 0, 100, 80, 20) $Progress_4 = GuiCtrlCreateProgress(0, 90, 220, 10) GuiSetState() While 1 $msg = GuiGetMsg() Select Case $msg = $GUI_EVENT_CLOSE ExitLoop Case Else If($loop=1) Then $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2") $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_Processor", "WQL", _ $wbemFlagReturnImmediately + $wbemFlagForwardOnly) If IsObj($colItems) then For $objItem In $colItems $Output = $objItem.LoadPercentage Next Endif $mem = MemGetStats () $var = ((($mem[1]-$mem[2])/$mem[1]) * 100) GUICtrlSetData ( $Progress_2, $var) $var = ((($mem[5] - $mem[6]) / $mem[5]) * 100) GUICtrlSetData ( $Progress_4, $var) $var = ((($mem[3] - $mem[4]) / $mem[3]) * 100) GUICtrlSetData ( $Progress_3, $var) GUICtrlSetData ( $Progress_1, $OutPut) EndIf EndSelect WEnd Exit Func toggle() if($loop=1)Then $loop=0 Else $loop=1 endif EndFunc But its kinda laggy , does anyone see anything to improve/change? Link to comment Share on other sites More sharing options...
w0uter Posted July 15, 2005 Share Posted July 15, 2005 IIRC the way you use $Output = $objItem.LoadPercentage only returns the LAST item's loadpercentage. My UDF's:;mem stuff_Mem;ftp stuff_FTP ( OLD );inet stuff_INetGetSource ( OLD )_INetGetImage _INetBrowse ( Collection )_EncodeUrl_NetStat_Google;random stuff_iPixelSearch_DiceRoll 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