当前位置:我的异常网» VC/MFC » 通过WMI获取系统硬件信息解决办法
通过WMI获取系统硬件信息解决办法
www.myexceptions.net,网友分享于:2013-01-01 浏览:352次
通过WMI获取系统硬件信息
找到一个采用VBS脚本,通过WMI获取系统信息的程序,代码如下:
On Error Resume Next
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" _
& strComputer & "\root\cimv2")
Set board = objWMIService.ExecQuery _
("Select * from Win32_BaseBoard")
For Each objItem in board
board2="主板:" & objItem.Product
Next
Set bios = objWMIService.ExecQuery _
("Select * from Win32_BIOS")
For Each objItem in bios
bios2="BIOS:" & objItem.Name & " (" & objItem.Version & ")"
Next
Set cpu = objWMIService.ExecQuery _
("Select * from Win32_Processor")
For Each objItem in cpu
cpu2="处理器:" & objItem.Name
Next
Set memory = objWMIService.ExecQuery _
("Select * from Win32_PhysicalMemory")
num=0
For Each objItem in memory
total=total+ objItem.Capacity/1048576
num=num+1
Next
memory2="内存:" & total & "M (" & num & ")"
Set disk = objWMIService.ExecQuery _
("Select * from Win32_DiskDrive")
For Each objItem in disk
disk2=disk2 & objItem.Model & " (" & round(objItem.Size/1073741824) & "G) , "
Next
disk2="硬盘:" & left(disk2,len(disk2)-4)
Set video = objWMIService.ExecQuery _
("Select * from Win32_VideoController")
For Each objItem in video
video2="显卡:" & objItem.Description
Next
Set sound = objWMIService.ExecQuery _
("Select * from Win32_SoundDevice")
For Each objItem in sound
sound2="声卡:" & objItem.Name
Next
Set lan = objWMIService.ExecQuery _
("Select * from Win32_NetworkAdapter")
For Each objItem in lan
if left(objItem.NetConnectionID,4)="本地连接" then
lan2=lan2 & "网卡:" & objItem.Name
exit for
end if
Next
Set cdrom = objWMIService.ExecQuery _
("Select * from Win32_CDROMDrive")
For Each objItem in cdrom
cdrom2=cdrom2 & objItem.Name & ", "
Next
cdrom2="光驱:" & left(cdrom2,len(cdrom2)-3)
Set computername = objWMIService.ExecQuery _
("Select * from Win32_ComputerSystem")
For Each objItem in computername
computername2=objItem.Name
Next
Set fso = CreateObject("Scripting.FileSystemObject")
filename="本机硬件信息 (" & computername2 &").txt"
Set f1 = fso.CreateTextFile(filename)
out=board2 & vbcrlf & _
bios2 & vbcrlf & _
cpu2 & vbcrlf & _
memory2 & vbcrlf & _
disk2 & vbcrlf & _
video2 & vbcrlf & _
sound2 & vbcrlf & _
lan2 & vbcrlf & _
cdrom2
f1.WriteLine(out)
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Run "%windir%\notepad " & filename
运行程序,感觉效果不错,想把VBS实现的程序,用MFC6实现,那位朋友做过,给点思路
------解决方案--------------------
http://www.codeguru.com/cpp/w-p/system/hardwareinformation/
相关解决方案
暂无相关解决方案