找回密码
 加入
搜索
查看: 3391|回复: 7

[系统综合] 获取硬盘序列号问题,求助高手

  [复制链接]
发表于 2015-12-17 16:36:34 | 显示全部楼层 |阅读模式
吸取高手的经验,虽然利用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
发表于 2015-12-17 16:43:33 | 显示全部楼层
 楼主| 发表于 2015-12-17 16:52:59 | 显示全部楼层
回复 2# ceoguang

这帖子运行错误呀
发表于 2015-12-17 17:58:27 | 显示全部楼层
回复 3# sarfar

   P大的无错

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?加入

×
 楼主| 发表于 2015-12-17 18:43:20 | 显示全部楼层
回复 4# 繁星


是没有错,在硬盘是IDE接口下可以用,在新的串口下无法获取
发表于 2015-12-18 09:04:18 | 显示全部楼层
用这个:
wmic diskdrive get SerialNumber
发表于 2015-12-18 10:22:39 | 显示全部楼层
#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
发表于 2015-12-18 11:26:26 | 显示全部楼层
; 生成于虫子樱桃自用汉化版 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
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-12-22 22:08 , Processed in 0.087353 second(s), 24 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表