获取硬盘序列号问题,求助高手
吸取高手的经验,虽然利用WMI可以获取硬盘序列号,但有些电脑重装下系统,发现序列号变了,变成用UNICODE格式的,而且顺序还乱了,求助高手提供个API获取的方法或者OS层获取的方法,谢谢。Dim $wen=__WMI_WIN32_DiskDrive_SerialNumber()
MsgBox(4096,"000",$wen,10)
Func __WMI_WIN32_DiskDrive_SerialNumber()
Local $WBEMFLAGRETURNIMMEDIATELY = 0x00000010
Local $WBEMFLAGFORWARDONLY = 0x00000020
Local $COLITEMS = ""
Local $STRCOMPUTER = "localhost"
Local $OUTPUT = ""
$OUTPUT &= "Computer: " & $STRCOMPUTER & @CRLF
$OUTPUT &= "==========================================" & @CRLF
Local $OBJWMISERVICE = ObjGet("winmgmts:\\" & $STRCOMPUTER & "\root\CIMV2")
$COLITEMS = $OBJWMISERVICE .ExecQuery("SELECT * FROM Win32_DiskDrive Where Index=0", "WQL", $WBEMFLAGRETURNIMMEDIATELY + $WBEMFLAGFORWARDONLY)
If @error Then Return ""
If IsObj($COLITEMS) Then
For $OBJITEM In $COLITEMS
Return $OBJITEM.SerialNumber
Next
Else
Return ""
EndIf
EndFunc
http://www.autoitx.com/forum.php?mod=viewthread&tid=9507&highlight=%D0%F2%C1%D0%BA%C5 回复 2# ceoguang
这帖子运行错误呀 回复 3# sarfar
P大的无错 回复 4# 繁星
是没有错,在硬盘是IDE接口下可以用,在新的串口下无法获取 用这个:
wmic diskdrive get SerialNumber #include <Array.au3>
Example()
Func Example()
Local $iPID = Run(@ComSpec & ' /C wmic diskdrive get SerialNumber | find /V "SerialNumber"', "", @SW_HIDE, $STDOUT_CHILD)
ProcessWaitClose($iPID)
Local $sOutput = StdoutRead($iPID)
Local $aArray = StringSplit(StringTrimRight(StringStripCR($sOutput), StringLen(@CRLF)), @CRLF)
_ArrayDisplay($aArray)
EndFunc ; 生成于虫子樱桃自用汉化版 AutoIt Scriptomatic
__wmi_Win32_DiskDrive()
Func __wmi_Win32_DiskDrive()
Local $wbemFlagReturnImmediately = 0x10
Local $wbemFlagForwardOnly = 0x20
Local $colItems = ""
Local $strComputer = "localhost"
Local $Output=""
$Output &= "Computer: " & $strComputer& @CRLF
$Output &= "==========================================" & @CRLF
Local $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2")
$colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_DiskDrive", "WQL", _
$wbemFlagReturnImmediately + $wbemFlagForwardOnly)
If IsObj($colItems) then
For $objItem In $colItems
$Output &= "SerialNumber: " & $objItem.SerialNumber & @CRLF
if Msgbox(1,"WMI输出",$Output) = 2 then ExitLoop
$Output=""
Next
Else
Msgbox(0,"WMI 输出","没有在类 " & "Win32_DiskDrive" & "中找到WMI对象" )
Endif
EndFunc
Func WMIDateStringToDate($dtmDate)
Return (StringMid($dtmDate, 5, 2) & "/" & _
StringMid($dtmDate, 7, 2) & "/" & StringLeft($dtmDate, 4) _
& " " & StringMid($dtmDate, 9, 2) & ":" & StringMid($dtmDate, 11, 2) & ":" & StringMid($dtmDate,13, 2))
EndFunc
页:
[1]