http://dieseyer.de • all rights reserved • © 2011 v11.4

'*** v9.B *** www.dieseyer.de ******************************
'
' Datei: ramnutzung.vbs
' Autor: dieseyer@gmx.de
'
' Zeigt die aktuelle Arbeitsspeicher-Nutzung:
' RAM- (realer Arbeitsspeicher) und
' virtueller Arbeitsspeicher (inkl. Auslagerungsdatei)
'
'***********************************************************

Option Explicit ' Siehe http://dieseyer.de/dse-wsh-lernen.html#OptionExpl

Dim PC : PC ="."
MsgBox SpeicherNutzung( PC ), , "15 :: " & WScript.ScriptName

WScript.Quit

'*** v9.B *** www.dieseyer.de ******************************
Function SpeicherNutzung( PC )
'***********************************************************
Const wbemFlagReturnImmediately = &h10
Const wbemFlagForwardOnly = &h20
Dim objWMIService : Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & PC & "\root\cimv2")

' RAM - realer Arbeitsspeicher
' ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Dim colItems : Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_OperatingSystem", "WQL", wbemFlagReturnImmediately + wbemFlagForwardOnly)
Dim objItem, MemFrei, MemTotal, t
MemFrei = 0 : MemTotal = 0
For Each objItem In colItems ' in kBytes

MemFrei = FormatNumber( objItem.FreePhysicalMemory / 1024*10, 0, 0, 0, -2 ) / 10
MemFrei = FormatNumber( objItem.FreePhysicalMemory / 1024 , 0, 0, 0, -2 )
MemFrei = FormatNumber( Round( objItem.FreePhysicalMemory / 1024 ), 0, 0, 0, -2 )
t = t & vbCRLF & "FreePhysicalMemory: " & MemFrei & "MB"

MemTotal = FormatNumber( objItem.TotalVisibleMemorySize / 1024*10, 0, 0, 0, -2 ) / 10
MemTotal = FormatNumber( objItem.TotalVisibleMemorySize / 1024 , 0, 0, 0, -2 )
MemTotal = FormatNumber( Round( objItem.TotalVisibleMemorySize / 1024 ), 0, 0, 0, -2 )
t = t & vbCRLF & "TotalVisibleMemorySize: " & MemTotal & "MB"
Next
SpeicherNutzung = "RAM: " & MemFrei & "MB (" & Round( MemFrei / MemTotal * 100 ) & "%) von " & MemTotal & "MB frei; "
' MsgBox SpeicherNutzung, , "44 :: "

' virtueller Arbeitsspeicher (inkl. Auslagerungsdatei)
' ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Dim VirtTotal, VirtAkt, VirtFrei
VirtTotal = 0 : VirtAkt = 0 : VirtFrei = 0
Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_PageFileSetting", "WQL", wbemFlagReturnImmediately + wbemFlagForwardOnly)
For Each objItem In colItems
VirtTotal = VirtTotal + objItem.MaximumSize
Next

Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_PageFileUsage", "WQL", wbemFlagReturnImmediately + wbemFlagForwardOnly)
For Each objItem In colItems
VirtAkt = VirtAkt + objItem.CurrentUsage
Next
VirtFrei = VirtTotal - VirtAkt
SpeicherNutzung = SpeicherNutzung & "Virt.: " & VirtFrei & "MB (" & Round( VirtFrei / VirtTotal * 100 ) & "%) von " & VirtTotal & "MB frei."
' MsgBox SpeicherNutzung, , "61 :: "

End Function ' SpeicherNutzung( PC )

http://dieseyer.de • all rights reserved • © 2011 v11.4