WMI范例与说明

1 strComputer = "atl-dc-01"

Set wbemServices = Getobject("winmgmts:\" & strComputer)

Set wbemObjectSet = wbemServices.InstancesOf("Win32_LogicalMemoryConfiguration")

For Each wbemObject In wbemObjectSet

    WScript.Echo "Total Physical Memory (kb): " & wbemObject.TotalPhysicalMemory

Next

'---------------------显示系统中的物理内存的容量

2 strComputer = "atl-dc-01"

Set wbemServices = Getobject("winmgmts:\" & strComputer)

Set wbemObjectSet = wbemServices.InstancesOf("Win32_Service")

For Each wbemObject In wbemObjectSet

    WScript.Echo "Display Name: " & wbemObject.DisplayName & vbCrLf & _

                 "   State:      " & wbemObject.State       & vbCrLf & _

                 "   Start Mode: " & wbemObject.StartMode

Next

'--------------------显示系统的服务信息

3 strComputer = "atl-dc-01"

Set wbemServices = Getobject("winmgmts:\" & strComputer)

Set wbemObjectSet = wbemServices.InstancesOf("Win32_NTLogEvent")

For Each wbemObject In wbemObjectSet

    WScript.Echo "Log File:        " & wbemObject.LogFile        & vbCrLf & _

                 "Record Number:   " & wbemObject.RecordNumber   & vbCrLf & _

                 "Type:            " & wbemObject.Type           & vbCrLf & _

                 "Time Generated: " & wbemObject.TimeGenerated & vbCrLf & _

                 "Source:          " & wbemObject.SourceName     & vbCrLf & _

                 "Category:        " & wbemObject.Category       & vbCrLf & _

                 "Category String: " & wbemObject.CategoryString & vbCrLf & _

                 "Event:           " & wbemObject.EventCode      & vbCrLf & _

                 "User:            " & wbemObject.User           & vbCrLf & _

                 "Computer:        " & wbemObject.ComputerName   & vbCrLf & _

                 "Message:         " & wbemObject.Message        & vbCrLf

Next

'--------------------------------读取Windows事件的日志