Code-Beispiel
CPU Auslastung ermitteln
Lizenz: | Erster Autor: | Letzte Bearbeitung: |
k. A. | csde_rats | 24.11.2007 |
Das geht ganz einfach:
' CPU-Auslastung ermitteln
DECLARE FUNCTION CPUAuslastung() As UByte
Do
Sleep 20
PRINT "Aktuelle CPU-Last:"; CPUAuslastung; "%"
loop
sleep
FUNCTION CPUAuslastung() As UByte
Dim cpu As String
OPEN ENVIRON("TEMP") + "\~CPULOAD.VBS" FOR OUTPUT AS 1
PRINT #1, "Option Explicit"
PRINT #1, ""
PRINT #1, "Dim oWMI, aCPU, oCPU, oFS, oTs"
PRINT #1, "Set oWMI = GetObject(" + CHR(34) + "winmgmts://." + CHR(34) + ")"
PRINT #1, "Set oFS = CreateObject(" + CHR(34) + "Scripting.FileSystemObject" + CHR(34) + ")"
PRINT #1, "Set oTs = oFS.CreateTextFile(" + CHR(34) + ENVIRON("TEMP") + "\~CPULOAD.TXT" + CHR(34) + ",True)"
PRINT #1, "Set aCPU = oWMI.InstancesOf(" + CHR(34) + "Win32_Processor" + CHR(34) + ")"
PRINT #1, "For Each oCPU In aCPU"
PRINT #1, " oTs.WriteLine CStr(oCPU.LoadPercentage)"
PRINT #1, "Next"
PRINT #1, "oTs.Close"
PRINT #1, "Set oTs = Nothing"
PRINT #1, "Set aCPU = Nothing"
PRINT #1, "Set oWMI = Nothing"
PRINT #1, "Set oFS = Nothing"
CLOSE 1
SHELL "cscript //NoLogo " + ENVIRON("TEMP") + "\~CPULOAD.VBS"
KILL ENVIRON("TEMP") + "\~CPULOAD.VBS"
OPEN ENVIRON("TEMP") + "\~CPULOAD.TXT" FOR INPUT AS 1
LINE INPUT #1, cpu
CLOSE 1
KILL ENVIRON("TEMP") + "\~CPULOAD.TXT"
Return VAL(cpu)
END FUNCTION
Zusätzliche Informationen und Funktionen | |||||||
---|---|---|---|---|---|---|---|
|