香港新浪網 MySinaBlog
« 上一篇 | 下一篇 »
Emily | 27th Nov 2006, 14:24 PM | Script | (1298 Reads)

WMI Example: Memory & Processor Speed

 

Sub WMIMemoryInfo()

    Set wmiObjSet = GetObject("winmgmts:{impersonationLevel=impersonate}"). _
                    instancesOf("Win32_PhysicalMemory")
    For Each objItem In wmiObjSet
        Debug.Print "BankLabel: " & objItem.BankLabel
        Debug.Print "Capacity: " & objItem.Capacity
        Debug.Print "Caption: " & objItem.Caption
        Debug.Print "DeviceLocator: " & objItem.DeviceLocator
        Debug.Print "Tag: " & objItem.Tag
    
Next
End Sub

Sub ProcessorSpeed()
    Dim MyOBJ As Object
    Dim cpu As Object
    Set MyOBJ = GetObject("WinMgmts:").instancesOf("Win32_Processor")
    For Each cpu In MyOBJ
        MsgBox cpu.Name & " " & cpu.CurrentClockSpeed & " Mhz", vbInformation
 
   Next
End Sub

Function TranslateDomainRole(ByVal roleID)
    Dim a

    Select Case roleID
        Case 0
            a = "Standalone Workstation"
        Case 1
            a = "Member Workstation"
        Case 2
            a = "Standalone Server"
        Case 3
            a = "Member Server"
        Case 4
            a = "Backup Domain Controller"
        Case 5
            a = "Primary Domain Controller"
    End Select
    TranslateDomainRole = a
End Function

Sub Test()

Dim s, System, item
Set System = GetObject("winmgmts:").instancesOf("Win32_ComputerSystem")
For Each item In System
    s = "Computer Info" & vbCrLf
    s = s & "***********************" & vbCrLf
    s = s & "Name: " & item.Name & vbCrLf
    s = s & "Status: " & item.Status & vbCrLf
    s = s & "Type: " & item.SystemType & vbCrLf
    s = s & "Mfg: " & item.Manufacturer & vbCrLf
    s = s & "Model: " & item.Model & vbCrLf
    s = s & "RAM: ~" & item.TotalPhysicalMemory 1024000 & "mb" & vbCrLf
    s = s & "Domain: " & item.Domain & vbCrLf
    s = s & "Role: " & TranslateDomainRole(item.DomainRole) & vbCrLf
    s = s & "Current User: " & item.UserName & vbCrLf
    MsgBox s
Next
End Sub

'

mySinaBlog 不支援斜線,斜線現用全形\取代 ,請改回。