用API 函數(shù)GetVolumeInformation得到的不是硬盤的序列號?。?!
公司主營業(yè)務:網(wǎng)站制作、成都做網(wǎng)站、移動網(wǎng)站開發(fā)等業(yè)務。幫助企業(yè)客戶真正實現(xiàn)互聯(lián)網(wǎng)宣傳,提高企業(yè)的競爭能力。成都創(chuàng)新互聯(lián)是一支青春激揚、勤奮敬業(yè)、活力青春激揚、勤奮敬業(yè)、活力澎湃、和諧高效的團隊。公司秉承以“開放、自由、嚴謹、自律”為核心的企業(yè)文化,感謝他們對我們的高要求,感謝他們從不同領域給我們帶來的挑戰(zhàn),讓我們激情的團隊有機會用頭腦與智慧不斷的給客戶帶來驚喜。成都創(chuàng)新互聯(lián)推出襄州免費做網(wǎng)站回饋大家。
BOOL GetVolumeInformation(
LPCTSTR lpRootPathName,
LPTSTR lpVolumeNameBuffer,
DWORD nVolumeNameSize,
LPDWORD lpVolumeSerialNumber,
LPDWORD lpMaximumComponentLength,
LPDWORD lpFileSystemFlags,
LPTSTR lpFileSystemNameBuffer,
DWORD nFileSystemNameSize
);
看看英文?。篤olumeSerialNumber!得到的只是卷區(qū)序列號!
硬盤的序列號應該是
Drive Model Number________________: WDC WD400EB-00CPF0
Drive Serial Number_______________: WD-WCAATF083586
Drive Controller Revision Number__: 06.04G06
Controller Buffer Size on Drive___: 2097152 bytes
Drive Type________________________: Fixed
Drive Size________________________: 40020664320 bytes
中:
Drive Serial Number_______________: WD-WCAATF083586 這才是硬盤Serial Number?。。。?/p>
這個號是不會因為你格式化硬盤而改動,也不是網(wǎng)上流傳的修改工具能改的,(其實網(wǎng)上流傳的修改工具的也不過是卷區(qū)號而已!)
建議用 DiskID.dll或DiskID32.dll來獲取
用diskid.dll和disk32.dll獲得硬盤序列號
1.調(diào)用diskid.dll實現(xiàn):
Option Explicit
Private Declare Function IsWinNT Lib "DiskID.DLL" () As Long
Private Declare Function ReadPhysicalDrive9X Lib "DiskID.DLL" (driveID As Long, buffer As Long, bufLen As Long) As Long
Private Declare Function ReadPhysicalDriveInNT Lib "DiskID.DLL" (driveID As Long, buffer As Long, bufLen As Long) As Long
Private Type DRIVER_INFO_OK
ModalNumber(39) As Byte
SerialNumber(19) As Byte
ControlNum(7) As Byte
DriveType As Long
Cylinders As Long
Heads As Long
Sectors As Long
End Type
Private Sub Command1_Click()
Dim x As DRIVER_INFO_OK
Dim i As Long
If IsWinNT = 1 Then
i = ReadPhysicalDriveInNT(ByVal 0, ByVal VarPtr(x), ByVal 256)
Else
i = ReadPhysicalDrive9X(ByVal 0, ByVal VarPtr(x), ByVal 256)
End If
Dim s As String
s = StrConv(x.ModalNumber, vbUnicode)
s = Left(s, InStr(1, s, Chr(0)) - 1)
MsgBox "硬件廠商代碼為:" + s
s = StrConv(x.SerialNumber, vbUnicode)
s = Left(s, InStr(1, s, Chr(0)) - 1)
MsgBox "硬盤序列號為:" + s
End Sub
2.調(diào)用diskid32.dll實現(xiàn):
Option Explicit
Private Declare Function DiskID32 Lib "DiskID32.DLL" (ByRef DiskModel As Byte, ByRef DiskID As Byte) As Long
Private Sub Command1_Click()
Dim DiskModel(31) As Byte, DiskID(31) As Byte, i As Integer, Model As String, ID As String
If DiskID32(DiskModel(0), DiskID(0)) 1 Then
MsgBox "get diskid32 err"
Exit Sub
End If
For i = 0 To 31
If Chr(DiskModel(i)) Chr(0) Then
Model = Model Chr(DiskModel(i))
End If
If Chr(DiskID(i)) Chr(0) Then
ID = ID Chr(DiskID(i))
End If
Next
MsgBox "硬件產(chǎn)生代碼為:" + Model
MsgBox "硬盤序列號為:" + ID
End Sub
說明:diskid.dll可從下載
diskid32.dll可從下載
Private Function 硬盤序列號() As String
Try
Dim myInfo As Microsoft.Win32.RegistryKey = My.Computer.Registry.LocalMachine.OpenSubKey("HARDWARE\DEVICEMAP\Scsi\Scsi Port 0\Scsi Bus 1\Target Id 0\Logical Unit Id 0")
硬盤序列號 = Trim(myInfo.GetValue("SerialNumber"))
Catch
Try
Dim myInfo As Microsoft.Win32.RegistryKey = My.Computer.Registry.LocalMachine.OpenSubKey("HARDWARE\DEVICEMAP\Scsi\Scsi Port 1\Scsi Bus 1\Target Id 0\Logical Unit Id 0")
硬盤序列號 = Trim(myInfo.GetValue("SerialNumber"))
Catch
硬盤序列號 = ""
End Try
End Try
End Function
只在我的電腦上試過,你試下
strResult += 磁盤類型: System.Convert.ToInt16(disk(DriveType).ToString())End IfMsgBox(strResult)NextEnd Sub總結:在VB.NET中,用API函數(shù)可以獲取硬盤信息。原來熟悉API函數(shù)VB6程序員,可以對API函數(shù)聲明進行適當?shù)母暮?,進行調(diào)用。利用FSO(文件系統(tǒng)對象)的Scrrun.DLL,也可以獲得磁盤信息。在.net Framwork中,利用WMI可以獲取更多的關于機器硬件的詳細信息(參考System.Management命名空間)。
Private Function 硬盤序列號() As String
Try
Dim myInfo As Microsoft.Win32.RegistryKey = My.Computer.Registry.LocalMachine.OpenSubKey("HARDWARE\DEVICEMAP\Scsi\Scsi Port 0\Scsi Bus 1\Target Id 0\Logical Unit Id 0")
硬盤序列號 = Trim(myInfo.GetValue("SerialNumber"))
Catch
Try
Dim myInfo As Microsoft.Win32.RegistryKey = My.Computer.Registry.LocalMachine.OpenSubKey("HARDWARE\DEVICEMAP\Scsi\Scsi Port 1\Scsi Bus 1\Target Id 0\Logical Unit Id 0")
硬盤序列號 = Trim(myInfo.GetValue("SerialNumber"))
Catch
硬盤序列號 = ""
End Try
End Try
End Function
試下,如果返回為空,則表示失敗。
在本機win8win8.1有效,不過好像在有些機器上沒用。
本文題目:vb.net硬盤號 vb讀取硬盤序列號
標題URL:http://www.rwnh.cn/article22/doocsjc.html
成都網(wǎng)站建設公司_創(chuàng)新互聯(lián),為您提供靜態(tài)網(wǎng)站、外貿(mào)網(wǎng)站建設、關鍵詞優(yōu)化、網(wǎng)站改版、域名注冊、網(wǎng)站策劃
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉載內(nèi)容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉載,或轉載時需注明來源: 創(chuàng)新互聯(lián)