进程的内存利用率

Memory utilisation of a process

我 运行 这个脚本在 Windows 7 中,但是我没有得到进程使用的正确内存:

Set objWMI = GetObject("winmgmts:\.\root\cimv2")
Set colObjects = objWMI.ExecQuery("Select * From Win32_Process where Caption='firefox.exe'")

For Each Item in colObjects
    WScript.Echo Item.Name & " - " & Item.WorkingSetSize
Next

我正在减去这样的值 -289210368

谁能帮我找到以兆字节 (MB) 为单位的正确内存?

尝试使用这个函数:Function ConvertSize(Size) 像这样:

Set objWMI = GetObject("winmgmts:\.\root\cimv2")
Set colObjects = objWMI.ExecQuery("Select * From Win32_Process where Caption='firefox.exe'")

For Each Item in colObjects
    WScript.Echo Item.Name & " = " & ConvertSize(Item.WorkingSetSize)
Next
'******************************************************************************************
Function ConvertSize(Size) 
    Do While InStr(Size,",") 'Remove commas from size     
        CommaLocate = InStr(Size,",")     
        Size = Mid(Size,1,CommaLocate - 1) & _         
        Mid(Size,CommaLocate + 1,Len(Size) - CommaLocate) 
    Loop
    Dim Suffix:Suffix = " Bytes" 
    If Size >= 1024 Then suffix = " KB" 
    If Size >= 1048576 Then suffix = " MB" 
    If Size >= 1073741824 Then suffix = " GB" 
    If Size >= 1099511627776 Then suffix = " TB" 
    Select Case Suffix    
    Case " KB" Size = Round(Size / 1024, 1)     
    Case " MB" Size = Round(Size / 1048576, 1)     
    Case " GB" Size = Round(Size / 1073741824, 1)     
    Case " TB" Size = Round(Size / 1099511627776, 1) 
    End Select
    ConvertSize = Size & Suffix 
End Function
'******************************************************************************************

如果你当然想将一些进程放入数组并检查它们的大小,你也可以像这样:

Option Explicit
Dim Title,ProcessArray,Process,Msg 
Title = "PROCESS SIZE by Hackoo 2015"
ProcessArray = Array("explorer.exe","firefox.exe","chrome.exe","iexplore.exe","Opera.exe",_
"Skype.exe","IDMan.exe","CCleaner.exe","svchost.exe","winlogon.exe","VLC.exe","wscript.exe","WINWORD.exe")  
    For Each Process In ProcessArray     
      Msg = Msg & Process & " = " & Process_Size(Process) & VbCrlF  
    Next  
MsgBox Msg,VbInformation,Title
'****************************************************************************************** 
Function Process_Size(ProcessName)  
Dim objWMI,colObjects,Item
Set objWMI = GetObject("winmgmts:\.\root\cimv2")
Set colObjects = objWMI.ExecQuery("Select * From Win32_Process where Caption= '"& ProcessName & "'")
For Each Item in colObjects
   Process_Size = ConvertSize(Item.WorkingSetSize)
Next
End Function
'******************************************************************************************
Function ConvertSize(Size) 
    Dim CommaLocate
    Do While InStr(Size,",") 'Remove commas from size     
        CommaLocate = InStr(Size,",")     
        Size = Mid(Size,1,CommaLocate - 1) & _         
        Mid(Size,CommaLocate + 1,Len(Size) - CommaLocate) 
    Loop
    Dim Suffix:Suffix = " Bytes" 
    If Size >= 1024 Then suffix = " KB" 
    If Size >= 1048576 Then suffix = " MB" 
    If Size >= 1073741824 Then suffix = " GB" 
    If Size >= 1099511627776 Then suffix = " TB" 
    Select Case Suffix    
    Case " KB" Size = Round(Size / 1024, 1)     
    Case " MB" Size = Round(Size / 1048576, 1)     
    Case " GB" Size = Round(Size / 1073741824, 1)     
    Case " TB" Size = Round(Size / 1099511627776, 1) 
    End Select
    ConvertSize = Size & Suffix 
End Function
'******************************************************************************************