|
本帖最后由 surongfu 于 2012-6-26 08:34 编辑
之前发过类似的问题,想把以下代码的输出方式改成文本输出
这是一个用dxdiag采集硬件信息的源码,准确性高,就是速度慢了点,wmi采集cpu不正确,上次我发的是注册表,发现在网吧无盘里采集还是不正确,采集出来都是一种显卡,声卡一大堆有好几种,用dxdiag我去试了几台都很准确,以下是dxdiag收集硬件信息的源码#include "DIY_InfoGet.au3"
$time = TimerInit()
ToolTip('正在获取硬件信息... 大概需要15秒左右!',@DesktopWidth / 2 ,@DesktopHeight / 2,"Dxdiag版—获取硬件信息 BBs.wglm.net 小A 版权所有" ,1,2)
$NetWork = _NetworkGet();注册表网卡型号获取
$diskinfo = _DiskGet();注册表硬盘型号获取
$Camer = _CameraGet();注册表摄像头型号获取
$DxdiagInfo = _DxdiagInfo();Dxdiag硬件信息
$videoInfo = _videoGet();注册表获取显示器大小
ToolTip('')
MsgBox(0,'Dxdiag版—获取硬件信息完毕 耗时:' & Round (TimerDiff($time) / 1000 ,0) & "秒" , "Dxdiag版—获取硬件信息" & @CRLF _
& @CRLF & "计算机名:" & $DxdiagInfo[0] _
& @CRLF & "操作系统:" & $DxdiagInfo[1] _
& @CRLF & "BIOS:" & $DxdiagInfo[3] _
& @CRLF & "处理器:" & $DxdiagInfo[4] _
& @CRLF & "主板:" & $DxdiagInfo[2] _
& @CRLF & "内存:" & $DxdiagInfo[5] _
& @CRLF & "硬盘:" & $diskinfo _
& @CRLF & "显卡:" & $DxdiagInfo[6] & $DxdiagInfo[7] _
& @CRLF & "声卡:" & $DxdiagInfo[8] _
& @CRLF & "网卡:" & $NetWork _
& @CRLF & "摄像头:" & $Camer _
& @CRLF & "显示器:" & $videoInfo _
& @CRLF & @CRLF & @TAB & @TAB & "转载请注明出处 bbs.wglm.net 小A 版权所有")
运行库名称DIY_InfoGet.au3源码如下;开源新版电脑硬件信息获取 (计算机、BIOS、主板、CPU、内存、硬盘、显卡、声卡、网卡、摄像头、显示器大小)
;由于系统WMI获取硬件信息时,在某些情况下获取不到的情况。于是就想到了用另类的方法来实现。
;虽然在速度上远远比不上WMI快,但出于能准确的获取到硬件信息。最终我放弃了WMI。经测试后完全可以用,
;现在共享给网盟的兄弟们。觉得好用的请支持一个。
;原理:利用dxdiag.exe(Windows 自带 DirectX诊断工具)获取(计算机名、BIOS、CPU、显卡、声卡、主板、等信息)
;利用注册表获取(网卡、摄像头、显示器大小)同时转载请注明 bbs.wglm.net 小A 版权所有。
;请保留原作者版权.
;注册表网卡型号获取
Func _NetworkGet()
Local $NetWork = ""
For $i = 1 To 100
$var = RegEnumKey("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\NetworkCards", $i)
If @error <> 0 Then ExitLoop
$NetWork &= RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\NetworkCards" & "" & $var, "Description") & " "
Next
Return $NetWork
EndFunc ;==>_NetworkGet
;注册表硬盘型号获取
Func _DiskGet()
Local $diskinfo = ""
For $i = 1 To 100
$var = RegEnumKey("HKEY_LOCAL_MACHINE\HARDWARE\DEVICEMAP\Scsi", $i)
If @error <> 0 Then ExitLoop
For $n = 1 To 3
$var2 = RegEnumKey("HKEY_LOCAL_MACHINE\HARDWARE\DEVICEMAP\Scsi" & $var, $n)
If @error <> 0 Then ExitLoop
For $p = 1 To 10
$var3 = RegEnumKey("HKEY_LOCAL_MACHINE\HARDWARE\DEVICEMAP\Scsi" & $var & "" & $var2, $p)
If @error <> 0 Then ExitLoop
If StringLeft($var3, 6) <> "target" Then ContinueLoop
$diskinfo &= RegRead("HKEY_LOCAL_MACHINE\HARDWARE\DEVICEMAP\Scsi" & $var & "" & $var2 & "" & $var3 & "\Logical Unit Id 0", "Identifier") & " "
Next
Next
Next
Return $diskinfo
EndFunc ;==>_DiskGet
;注册表摄像头型号获取
Func _CameraGet()
$readubs = RegRead('HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Class\{6BDD1FC6-810F-11D0-BEC7-08002BE2092F}\0000', 'FriendlyName')
Return $readubs
EndFunc ;==>_CameraGet
;Dxdiag硬件信息
Func _DxdiagInfo()
Dim $DxdiagGet[9]
$dxdiagInfoPath = @SystemDir & "\dxdiaginfo.dat";读取报告
FileDelete($dxdiagInfoPath);删除dxdiag读取报告
RunWait("dxdiag.exe /whql:off /t " & $dxdiagInfoPath);运行dxdiag,收集硬件信息
$file = FileRead($dxdiagInfoPath)
$DxdiagGet[0] = _GetFiledate($file, "Machine name:");计算机名
$DxdiagGet[1] = _GetFiledate($file, "Operating System:");操作系统
$DxdiagGet[2] = _GetFiledate($file, "System Model:");主板
$DxdiagGet[3] = _GetFiledate($file, "BIOS:");Bios
$DxdiagGet[4] = _GetFiledate($file, "Processor:");CPu
$DxdiagGet[5] = _GetFiledate($file, "Memory:");内存
$DxdiagGet[6] = _GetFiledate($file, "Card name:") ;显卡
$DxdiagGet[7] = _GetFiledate($file, "Display Memory:");显卡内存
$DxdiagGet[8] = _GetFiledate($file, "Description:") ;声卡
FileDelete($dxdiagInfoPath);删除dxdiag读取报告
Return $DxdiagGet
EndFunc ;==>_DxdiagInfo
;获取Dxdiag文件数据
Func _GetFiledate($file, $string)
$str = StringInStr($file, $string)
$Mid = StringMid($file, $str + StringLen($string))
$date = StringSplit($Mid, @CRLF)
Return $date[1]
EndFunc ;==>_GetFiledate
;获取显示器信息,本信息取至于注册表Edid,可能会导致不准确、
Func _videoGet()
Local $xsInfo = "";声明变量,为防止系统WMI异常导致变量没申明.
$objWMIService = ObjGet("winmgmts:\\.\root\cimv2")
$colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_DesktopMonitor")
For $Info In $colItems
$xsInfo = $Info.PNPDeviceID
Next
$readLcd = "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Enum" & $xsInfo & "\Device Parameters"
$Edid = RegRead($readLcd, 'EDID')
$x = StringMid($Edid, 45, 2)
$x = Dec($x) ;显示器长度
$y = StringMid($Edid, 47, 2)
$y = Dec($y) ;显示器宽度
$z = StringMid($Edid, 35, 2)
$z = Dec($z) ;生产周
$u = StringMid($Edid, 37, 2)
$u = Dec($u) ;生产日期
$xx = Round(($x * $x), 0)
$yy = Round(($y * $y), 0)
$sqrt = Sqrt($xx + $yy);求平方根.
$main = Round($sqrt * 0.393700787, 1)
If $main = 0 Then Return '-1'
Return $main & "英寸(" & $x & "厘米 X " & $y & "厘米) 生产日期:" & ("1990" + $u) & "年 第 " & $z & " 周"
EndFunc ;==>_videoGet
但这个无法精确获取内存总量条数,补上一段精确代码,如下Global $objwmiservice,$wnc,$mem1, $mem3
Local $object, $objoperatingsystem
$objwmiservice = ObjGet("winmgmts:{impersonationlevel=impersonate}!\\.\root\cimv2")
$wnc = $objwmiservice.execquery("select * from win32_physicalmemory")
For $object In $wnc
$mem = String(Int($object.capacity / 1048576))
If $mem1 = "" Then
$mem1 = $mem & "MB"
$mem2 = ""
Else
$mem1 &= "/" & $mem & "MB"
$mem2 = "(" & $mem1 & ")"
EndIf
$mem3 += $mem
Next
$nc = $mem3 & "MB" & $mem2
MsgBox (32,"",$nc)
照上次A大帮我输出的方法,这次就不行了老提示错误,A大麻烦你在帮我输出一下吧谢谢先
要在以下代码中调用他的声卡要怎么调用#include 'DIY_RegInfo.au3'
Local $sFile = IniRead(@ScriptDir & "\config.ini", "config", 1, 1)
IniWrite($sFile, '硬件信息', @ComputerName, '主板:' & _MbGet() & ',处理器:' & _CpuGet() & ',显卡:' & _VGAGet() & ',声卡:' & _Realinfo() & @CRLF)
;;;以下为读取
Local $sInfo = IniRead($sFile, '硬件信息', @ComputerName, '读取错误')
MsgBox(0, '', $sInfo)
Func _MbGet()
Local $objWMIService = ObjGet('winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2')
Local $colBoard = $objWMIService.ExecQuery('SELECT * FROM Win32_BaseBoard')
For $object In $colBoard
Local $mb = $object.Product
Next
Return $mb
EndFunc ;==>_MbGet
|
|