模块/类模块
利用GetObject("WinMgmts:")获取系统信息-CPU 硬盘 网卡 显卡等信息
2017-06-09 17:20:59

利用GetObject("WinMgmts:")获取系统信息

一、用WMI对象列出系统所有进程: ----Instance.vbs---- 程序代码 Dim WMI,objsSet WMI = GetObject("WinMgmts:")Set objs = WMI.InstancesOf("Win32_Process") For Each obj In objs Enum1 = Enum1 + obj.Description + Chr(13) + Chr(10) Nextmsgbox Enum1二、获得物理内存的容量: -----physicalMemory.vbs----- 程序代码 strComputer = "." Set wbemServices = GetObject("winmgmts:\\" & strComputer) Set wbemObjectSet = wbemServices.InstancesOf("Win32_LogicalMemoryConfiguration") For Each wbemObject In wbemObjectSet WScript.Echo "物理内存 (MB): " & CInt(wbemObject.TotalPhysicalMemory/1024)Next 三、取得系统所有服务及运行状态 ----service.vbs---- 程序代码 Set ServiceSet = GetObject("winmgmts:").InstancesOf("Win32_Service")Dim s,inforinfor=""for each s in ServiceSetinfor=infor+s.Description+" ==> "+s.State+chr(13)+chr(10)nextmsgbox infor四、用WMI对象列出系统所有进程: ----Instance.vbs----程序代码 Dim WMI,objsSet WMI = GetObject("WinMgmts:")Set objs = WMI.InstancesOf("Win32_Process") For Each obj In objs Enum1 = Enum1 + obj.Description + Chr(13) + Chr(10) Nextmsgbox Enum1五、获得物理内存的容量: -----physicalMemory.vbs-----程序代码 strComputer = "." Set wbemServices = GetObject("winmgmts:\\" & strComputer) Set wbemObjectSet = wbemServices.InstancesOf("Win32_LogicalMemoryConfiguration") For Each wbemObject In wbemObjectSet WScript.Echo "物理内存 (MB): " & CInt(wbemObject.TotalPhysicalMemory/1024)Next 六、取得系统所有服务及运行状态 ----service.vbs----程序代码 Set ServiceSet = GetObject("winmgmts:").InstancesOf("Win32_Service")Dim s,inforinfor=""for each s in ServiceSetinfor=infor+s.Description+" ==> "+s.State+chr(13)+chr(10)nextmsgbox infor七、CPU的序列号: ---CPUID.vbs--- 程序代码 Dim cpuInfocpuInfo = ""set moc = GetObject("Winmgmts:").InstancesOf("Win32_Processor")for each mo in moccpuInfo = CStr(mo.ProcessorId)msgbox "CPU SerialNumber is : " & cpuInfonext硬盘型号: ---HDID.vbs---程序代码 Dim HDid,mocset moc =GetObject("Winmgmts:").InstancesOf("Win32_DiskDrive")for each mo in mocHDid = mo.Modelmsgbox "硬盘型号为:" & HDidnext八、网卡MAC物理地址: ---MACAddress.vbs---程序代码 Dim mcset mc=GetObject("Winmgmts:").InstancesOf("Win32_NetworkAdapterConfiguration")for each mo in mcif mo.IPEnabled=true thenmsgbox "网卡MAC地址是: " & mo.MacAddressexit forend ifnext九、测试你的显卡: 程序代码 On Error Resume NextDim yeDim yexj00 set yexj00=GetObject("winmgmts:{impersonationLevel=impersonate}").InstancesOf("Win32_VideoController") for each ye in yexj00 msgbox " 型 号: " & ye.VideoProcessor & vbCrLf & " 厂 商: " & ye.AdapterCompatibility & vbCrLf & " 名 称: " & ye.Name & vbCrLf & " 状 态: " & ye.Status & vbCrLf & " 显 存: " & (ye.AdapterRAM\1024000) & "MB" & vbCrLf & "驱 动 (dll): " & ye.InstalledDisplayDrivers & vbCrLf & "驱 动 (inf): " & ye.infFilename & vbCrLf & " 版 本: " & ye.DriverVersionnext