Hallo,
kann man irgendwie schnell/ ohne include, die cpu-auslastung/ ram/ benutzen ram abfragen?
Hallo,
kann man irgendwie schnell/ ohne include, die cpu-auslastung/ ram/ benutzen ram abfragen?
Hi,
WMI ist das Stichwort ... ![]()
Musste mal hier im Forum suchen, da dürfte einiges dabei sein.
Gruß
Greenhorn
#include <ProgressConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
Opt("GUIOnEventMode", 1)
[/autoit] [autoit][/autoit] [autoit]Local $CenterWidth = (@DesktopWidth - 200) / 2
Local $CenterHeight = (@DesktopHeight - 300) / 2
$wbemFlagReturnImmediately = 0x10
$wbemFlagForwardOnly = 0x20
$colItems = ""
$strComputer = "localhost"
$objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2")
; ============================================================================
; GUI Definition
; ============================================================================
$gui = GUICreate("CPU Meter", 200, 300, $CenterWidth, $CenterHeight, -1, $WS_EX_TOPMOST)
GUISetOnEvent(-3, "_Exit_Event", $gui)
GUISetIcon(@SystemDir & "\shell32.dll", 12)
GUICtrlCreateLabel("CPU1", 5, 3, 40, 20, $SS_CENTER)
$progressbar_core1 = GUICtrlCreateProgress(10, 20, 30, 250, $PBS_VERTICAL)
$label_core1 = GUICtrlCreateLabel("", 10, 275, 30, 20, $SS_CENTER)
GUICtrlCreateLabel("CPU2", 55, 3, 40, 20, $SS_CENTER)
$progressbar_core2 = GUICtrlCreateProgress(60, 20, 30, 250, $PBS_VERTICAL)
$label_core2 = GUICtrlCreateLabel("", 60, 275, 30, 20, $SS_CENTER)
GUICtrlCreateLabel("CPU3", 105, 3, 40, 20, $SS_CENTER)
$progressbar_core3 = GUICtrlCreateProgress(110, 20, 30, 250, $PBS_VERTICAL)
$label_core3 = GUICtrlCreateLabel("", 110, 275, 30, 20, $SS_CENTER)
GUICtrlCreateLabel("CPU4", 155, 3, 40, 20, $SS_CENTER)
$progressbar_core4 = GUICtrlCreateProgress(160, 20, 30, 250, $PBS_VERTICAL)
$label_core4 = GUICtrlCreateLabel("", 160, 275, 30, 20, $SS_CENTER)
GUISetState()
[/autoit] [autoit][/autoit] [autoit]; ============================================================================
; Main Loop
; ============================================================================
While 1
$colItems = $objWMIService.ExecQuery ("SELECT LoadPercentage FROM Win32_Processor", "WQL", $wbemFlagReturnImmediately + $wbemFlagForwardOnly)
If IsObj($colItems) Then
$i = 0
For $objItem In $colItems
If $i = 0 Then
GUICtrlSetData($progressbar_core1, $objItem.LoadPercentage)
GUICtrlSetData($label_core1, $objItem.LoadPercentage & "%")
ElseIf $i = 1 Then
GUICtrlSetData($progressbar_core2, $objItem.LoadPercentage)
GUICtrlSetData($label_core2, $objItem.LoadPercentage & "%")
ElseIf $i = 2 Then
GUICtrlSetData($progressbar_core3, $objItem.LoadPercentage)
GUICtrlSetData($label_core3, $objItem.LoadPercentage & "%")
ElseIf $i = 3 Then
GUICtrlSetData($progressbar_core4, $objItem.LoadPercentage)
GUICtrlSetData($label_core4, $objItem.LoadPercentage & "%")
EndIf
$i += 1
Next
Else
MsgBox(0, "WMI Output", "No WMI Objects Found for class: " & "Win32_Processor")
EndIf
WEnd
; ============================================================================
; Functions
; ============================================================================
Func _Exit_Event()
Exit
EndFunc ;==>_Exit_Event
Hier eine weitere Möglichkeit:
[ gelöst ] CPU Auslastung Auslesen
Es wird Calc.exe geöffnet. Einfach was berechnen, z.B. 99999999!
Gruß,
UEZ
Hier auch noch eine :
$objRefresher = ObjCreate("WbemScripting.SWbemRefresher")
[/autoit] [autoit][/autoit] [autoit]$objWMIService = ObjGet("winmgmts:\\localhost\root\CIMV2")
[/autoit] [autoit][/autoit] [autoit]$objRefreshableItem = $objRefresher.AddEnum($objWMIService , "Win32_PerfFormattedData_PerfOS_Processor")
[/autoit] [autoit][/autoit] [autoit]$objRefresher.Refresh
[/autoit] [autoit][/autoit] [autoit]If IsObj($objRefreshableItem) Then
$i = 0
For $objItem In $objRefreshableItem.ObjectSet
$i += 1
Next
EndIf
Global $aCPU[$i]
While 1
[/autoit] [autoit][/autoit] [autoit]$objRefresher.Refresh
If IsObj($objRefreshableItem) Then
$i = 0
For $objItem In $objRefreshableItem.ObjectSet
$aCPU[$i] = $objItem.PercentProcessorTime
$i += 1
Next
EndIf
ConsoleWrite("============" & @CRLF)
For $i = 0 To UBound($aCPU)-2
ConsoleWrite("Core "&$i+1&": "&$aCPU[$i] & @CRLF)
Next
ConsoleWrite("Gesamt: "&$aCPU[UBound($aCPU)-1] & @CRLF)
Sleep(500)
WEnd
Func OnAutoItExit()
$objRefresher.DeleteAll
EndFunc
Wie umständlich ihr denkt o.o
;==============================================
; Sen - CpuAuslastung
; Return: Cpu Auslastung (%)
;==============================================
Func CpuAuslastung()
Global $wbemFlagReturnImmediately = 0x10
Global $wbemFlagForwardOnly = 0x20
Global $wbemFlags = $wbemFlagReturnImmediately + $wbemFlagForwardOnly
Global $strComputer = @ComputerName
Global $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2")
Global $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_Processor", "WQL", $wbemFlags)
$n = 0
$c = 0
$sMsg = ""
For $objItem In $colItems
$sMsg &= "cpu%" & $objItem.LoadPercentage
$n += 1
Next
$CpuAuslastung = StringSplit($sMsg, "cpu%", 1)
[/autoit] [autoit][/autoit] [autoit]For $n = "0" To $CpuAuslastung[0]
$c += $CpuAuslastung[$n]
Next
Return (Round($c / $CpuAuslastung[0], 0) & "%")
EndFunc ;==>CpuAuslastung
Alles anzeigenWie umständlich ihr denkt o.o
Spoiler anzeigen
[autoit][/autoit] [autoit][/autoit] [autoit]
;==============================================
; Sen - CpuAuslastung
; Return: Cpu Auslastung (%)
;==============================================
Func CpuAuslastung()
Global $wbemFlagReturnImmediately = 0x10
Global $wbemFlagForwardOnly = 0x20
Global $wbemFlags = $wbemFlagReturnImmediately + $wbemFlagForwardOnly
Global $strComputer = @ComputerNameGlobal $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2")
[/autoit] [autoit][/autoit] [autoit]
Global $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_Processor", "WQL", $wbemFlags)$n = 0
[/autoit] [autoit][/autoit] [autoit]
$c = 0
$sMsg = ""
For $objItem In $colItems
$sMsg &= "cpu%" & $objItem.LoadPercentage
$n += 1
Next$CpuAuslastung = StringSplit($sMsg, "cpu%", 1)
[/autoit] [autoit][/autoit] [autoit]For $n = "0" To $CpuAuslastung[0]
[/autoit] [autoit][/autoit] [autoit]
$c += $CpuAuslastung[$n]
NextReturn (Round($c / $CpuAuslastung[0], 0) & "%")
[/autoit]
EndFunc ;==>CpuAuslastung
Warum umständlich?
Meins zeigt noch den Speicherverbrauch und die CPU Zeit an, ohne WMI! ![]()
WMI wird nur dazu benutzt die logischen CPUs zu bestimmen!
UEZ
Naja, der threadersteller wollte die Cpu Auslastung.
Die gibt meine Funktion auch wieder ![]()
Viele Wege führen nach Rom... ![]()
UEZ
hey, dank euch. hab mir grad mal alle sachen angeguckt, sind sehr schöne sachen bei.
brauch das ganze nur als momentaufnahme als text, werd mir also das passende aus den funcs raussuchen.
aber großes danke