找回密码
 加入
搜索
查看: 5695|回复: 11

[系统综合] 如何获取硬盘的物理序列号

 火.. [复制链接]
发表于 2011-7-2 10:01:18 | 显示全部楼层 |阅读模式
请问有关于获取硬盘物理序列号的代码么
发表于 2011-7-2 10:06:12 | 显示全部楼层
你都不会先搜一下?
发表于 2011-7-2 12:13:05 | 显示全部楼层
DriveGetSerial ( "路径" )
发表于 2011-7-2 15:35:22 | 显示全部楼层
UDF里也有哦,搜索一下吧
发表于 2011-7-3 19:23:36 | 显示全部楼层
我也想知道
发表于 2011-7-3 22:44:37 | 显示全部楼层
本帖最后由 水木子 于 2011-7-3 22:45 编辑

4楼的回复不对!
本论坛大神P版主写过相关UDF函数。
http://www.autoitx.com/forum.php ... 9507&highlight=
 楼主| 发表于 2011-7-4 13:53:08 | 显示全部楼层
积分不够看不到`
发表于 2011-7-8 03:46:43 | 显示全部楼层
本帖最后由 pusofalse 于 2011-3-15 22:48 编辑
#include <WinAPI.au3>

Const $IOCTL_STORAGE_BASE = 0x2D
Const $IOCTL_STORAGE_QUERY_PROPERTY = _MakeCtrlCode($IOCTL_STORAGE_BASE, 0x500)
Const $DFP_RECEIVE_DRIVE_DATA = 0x7C088

Const $tagSTORAGEPROPERTYQUERY = "int PropertyId;int QueryType;byte AdditionalParams"
Const $tagSTORAGEDEVICEDESCRIPTOR = "ulong Version;ulong Size;byte DeviceType;" & _
                        "byte DeviceTypeModifier;byte RemovableMedia;" & _
                        "byte CommandQueueing;ulong VendorIdOffset;" & _
                        "ulong ProductIdOffset;ulong ProductRevisionOffset;" & _
                        "ulong SerialNumberOffset;int BusType;" & _
                        "ulong RawPropertiesLength;byte RawDeviceProperties"
Const $tagDRIVERSTATUS = "byte DriverError;byte IDEStatus;byte Reserved1[2];dword Reserved2[2]"
Const $tagIDEREGS = "byte Features;byte SectorCount;byte SectorNumber;byte CylLow;" & _
                        "byte CylHigh;byte DriveHead;byte Command;byte Reserved"
Const $tagSENDCMDOUTPARAMS = "dword Size;" & $tagDRIVERSTATUS
Const $tagSENDCMDINPARAMS = "dword Size;" & $tagIDEREGS & ";byte DriveNumber;" & _
                        "byte Reserved1[3];dword Reserved2[4];byte Buffer"

$sPhysDisk = "\\.\PhysicalDrive0"
$hDisk = _WinAPI_CreateFile($sPhysDisk, 2, 6, 6, 1)
If $hDisk = -1 Then
        Exit(ConsoleWrite("_WinAPI_CreateFile fails, error code: " & _WinAPI_GetLastError() & @CRLF))
EndIf

$tSCIP = DllStructCreate($tagSENDCMDINPARAMS)
$tSCOP = DllStructCreate($tagSENDCMDOUTPARAMS & ";char Buffer[1024]")
$tQuery = DllStructCreate($tagSTORAGEPROPERTYQUERY)
$tDescr = DllStructCreate($tagSTORAGEDEVICEDESCRIPTOR)
DllStructSetData($tQuery, "PropertyId", 0)
DllStructSetData($tQuery, "QueryType", 0)

$iResult = _DeviceIoControl($hDisk, $IOCTL_STORAGE_QUERY_PROPERTY, _
                $tQuery, DllStructGetSize($tQuery), _
                $tDescr, DllStructGetSize($tDescr))
If $iResult = 0 Then
        Exit(ConsoleWrite("_DeviceIoControl fails, error code: " & @error & @CRLF))
EndIf

If DllStructGetData($tDescr, "BusType") = 2 Then
        DllStructSetData($tSCIP, "Command", 0xA1)
Else
        DllStructSetData($tSCIP, "Command", 0xEC)
EndIf

$iResult = _DeviceIoControl($hDisk, $DFP_RECEIVE_DRIVE_DATA, _
                $tSCIP, DllStructGetSize($tSCIP), _
                $tSCOP, DllStructGetSize($tSCOP))
If $iResult = 0 Then
        Exit(ConsoleWrite("_DeviceIoControl fails, error code: " & @error & @CRLF))
EndIf

Dim $sSerialNum
For $i = 21 to 40 Step 2
        $sSerialNum &= DllStructGetData($tSCOP, "Buffer", $i + 1)
        $sSerialNum &= DllStructGetData($tSCOP, "Buffer", $i)
Next
$sSerialNum = StringReplace($sSerialNum, " ", "")
Msgbox(0, "", $sPhysDisk & "'s serial number: " & $sSerialNum)

$tSCIP = 0
$tSCOP = 0
$tQuery = 0
$tDescr = 0
_WinAPI_CloseHandle($hDisk)

Func _MakeCtrlCode($iDevType, $iFunction, $iMethod = 0, $iAccess = 0)
        Return bitOR(bitShift($iDevType,-16),bitShift($iAccess, -14),bitShift($iFunction, -2), $iMethod)
EndFunc        ;==>_MakeCtrlCode

Func _DeviceIoControl($hDevice, $iCtrlCode, $pIn, $iIn, $pOut, $iOut, $pOverlapped = 0)
        Local $iResult

        If IsDllStruct($pIn) Then $pIn = DllStructGetPtr($pIn)
        If IsDllStruct($pOut) Then $pOut = DllStructGetPtr($pOut)
        If IsDllStruct($pOverlapped) Then $pOverlapped = DllStructGetPtr($pOverLapped)
        $iResult = DllCall("Kernel32.dll", "int", "DeviceIoControl", "ptr", $hDevice, _
                        "dword", $iCtrlCode, "ptr", $pIn, "dword", $iIn, _
                        "ptr", $pOut, "dword", $iOut, "int*", 0, "ptr", $pOverlapped)
        Return SetError(_WinAPI_GetLastError(), $iResult[7], $iResult[0])
EndFunc        ;==>_DeviceIoControl
发表于 2011-7-8 17:42:41 | 显示全部楼层
好东东顶,,,,,
发表于 2011-7-8 18:41:21 | 显示全部楼层
$sn = dllcall("DiskSerial.dll","int","GetSerialNumber","int","nDrive","str","lpBuffer")
$sn[2]
DiskSerial.dll自己去下载.我就不上传了
发表于 2011-7-9 10:14:37 | 显示全部楼层
这个好啊~~~~
发表于 2011-7-9 11:04:09 | 显示全部楼层
没怎么看明白
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-11-14 14:12 , Processed in 0.086177 second(s), 23 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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