很多年前写的一个小工具里面的一部分代码,刚才复制出来测试了一下,还可以用,核心的代码好像也是以前从别人的脚本里借鉴的,楼主用这种方式来获取吧,比写到文件再读取出来的方式要可靠一些,参数可以是IP地址,也可以是计算机名称,很老的脚本了,不足之处请见谅。$lines = _hardware("homepc")
ConsoleWrite($lines)
Func _hardware($ip)
dim $mbd,$MBD,$MEM,$VGA,$HDD,$CPU
If ping($ip,100) Then
$objWMIService = objget("winmgmts:{impersonationLevel=impersonate}!\\"& $ip & "\root\cimv2")
If Not @error Then
$colBoard = $objWMIService.ExecQuery("SELECT * FROM Win32_BaseBoard")
$colCPU = $objWMIService.ExecQuery("Select * from CIM_Processor")
$colMemory = $objWMIService.ExecQuery("Select * from Win32_ComputerSystem")
$colVideoinfo = $objWMIService.ExecQuery("Select * from Win32_VideoController")
$coldisk = $objWMIService.ExecQuery("Select * from Win32_DiskDrive")
For $object in $colBoard
$MBD = $object.Product
Next
For $object in $colCPU
$CPU = StringStripWS($object.Name,1)
Next
for $object in $colMemory
$MEM = string(Int(Number($object.TotalPhysicalMemory)/1048576)) & " MB"
Next
For $object in $colVideoinfo
$VGA = StringStripWS($object.Description ,1)
Next
For $object in $coldisk
$HDD = $HDD + int($object.size /1073741824)
Next
$HDD = String($HDD) & " GB"
Else
$CPU = "对方未开启WMI服务或用户名密码错误"
EndIf
Else
$CPU = "对方可能未开机"
EndIf
Return $IP & "|" & $MBD & "|" & $CPU & "|" & $MEM & "|" & $VGA & "|" & $HDD
EndFunc
|