Ⅰ VB 讀硬碟序列號
我用16進制顯示,有個性
Private Declare Function 獲得硬碟序列號 Lib "kernel32" Alias "GetVolumeInformationA" (ByVal lpRootPathName As String, ByVal lpVolumeNameBuffer As String, ByVal nVolumeNameSize As Long, lpVolumeSerialNumber As Long, lpMaximumComponentLength As Long, lpFileSystemFlags As Long, ByVal lpFileSystemNameBuffer As String, ByVal nFileSystemNameSize As Long) As Long
Private Sub Form_Load()
On Error GoTo Err_Form_Load
Dim AA, 硬碟序列號, Maxlen, Sysflag As Long: Dim VolName, FsysName As String
AA = 獲得硬碟序列號("c:\", VolName, 256, 硬碟序列號, Maxlen, Sysflag, FsysName, 256)
Form1.Caption = "C硬碟序列號(16制): " & Hex(硬碟序列號)
Exit Sub
Err_Form_Load:
End Sub
Ⅱ vb 獲取硬碟序列號序列號
Option Explicit
Private Declare Function GetVolumeInformation& Lib "kernel32" Alias "GetVolumeInformationA" (ByVal lpRootPathName As String, ByVal pVolumeNameBuffer As String, ByVal nVolumeNameSize As Long, lpVolumeSerialNumber As Long, lpMaximumComponentLength As Long, lpFileSystemFlags As Long, ByVal lpFileSystemNameBuffer As String, ByVal nFileSystemNameSize As Long)
Const MAX_FILENAME_LEN = 256
Private Sub Form_Load()
Dim RetVal As Long
Dim str As String * MAX_FILENAME_LEN
Dim str2 As String * MAX_FILENAME_LEN
Dim A As Long
Dim B As Long
Me.Show
Call GetVolumeInformation("C:\", str, MAX_FILENAME_LEN, RetVal, A, B, str2, MAX_FILENAME_LEN)
Text1 = RetVal
End Sub
Ⅲ VB中如何獲取主板或硬碟的序列號,網上搜到的一些,看得不太明白,代碼太多,有的還要進行一些復雜的
Function Comput()
On Error Resume Next
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_BaseBoard", , 48)
For Each objItem In colItems
Debug.Print "Caption: " & objItem.Caption
Debug.Print "ConfigOptions: " & objItem.ConfigOptions
Debug.Print "CreationClassName: " & objItem.CreationClassName
Debug.Print "Depth: " & objItem.Depth
Debug.Print "Description: " & objItem.Description
Debug.Print "Height: " & objItem.Height
Debug.Print "HostingBoard: " & objItem.HostingBoard
Debug.Print "HotSwappable: " & objItem.HotSwappable
Debug.Print "InstallDate: " & objItem.InstallDate
Debug.Print "Manufacturer: " & objItem.Manufacturer
Debug.Print "Model: " & objItem.Model
Debug.Print "Name: " & objItem.Name
Debug.Print "OtherIdentifyingInf " & objItem.OtherIdentifyingInfo
Debug.Print "PartNumber: " & objItem.PartNumber
Debug.Print "PoweredOn: " & objItem.PoweredOn
Debug.Print "Proct: " & objItem.Proct
Debug.Print "Removable: " & objItem.Removable
Debug.Print "Replaceable: " & objItem.Replaceable
Debug.Print "RequirementsDescription: " & objItem.RequirementsDescription
Debug.Print "RequiresDaughterBoard: " & objItem.RequiresDaughterBoard
Debug.Print "SerialNumber: " & objItem.SerialNumber
Debug.Print "SKU: " & objItem.SKU
Debug.Print "SlotLayout: " & objItem.SlotLayout
Debug.Print "SpecialRequirements: " & objItem.SpecialRequirements
Debug.Print "Status: " & objItem.Status
Debug.Print "Tag: " & objItem.Tag
Debug.Print "Version: " & objItem.Version
Debug.Print "Weight: " & objItem.Weight
Debug.Print "Width: " & objItem.Width
Debug.Print
Next
End Function
注意:SerialNumber 所在的行就是
Ⅳ VB裡面怎麼獲取硬碟編號
Private Declare Function MymachineC Lib "kernel32" Alias "GetVolumeInformationA" (ByVal lpRootPathName As String, ByVal lpVolumeNameBuffer As String, ByVal nVolumeNameSize As Long, lpVolumeSerialNumber As Long, lpMaximumComponentLength As Long, lpFileSystemFlags As Long, ByVal lpFileSystemNameBuffer As String, ByVal nFileSystemNameSize As Long) As Long
Private Sub Command1_Click()
Dim DiskId, Maxlen, Sysflag As Long: Dim VolName, FsysName As String
Call MymachineC("c:\", VolName, 256, DiskId, Maxlen, Sysflag, FsysName, 256)
MsgBox "序列號:" & DiskId
End Sub
這個能獲取C盤的序列號 但是 格式化/重做系統後 就會變!
Ⅳ win64 下如何用VB獲取硬碟參數,序列號
private Declare Function MymachineC Lib "kernel32" Alias "GetVolumeInformationA" (ByVal lpRootPathName As String, ByVal lpVolumeNameBuffer As String, ByVal nVolumeNameSize As Long, lpVolumeSerialNumber As Long, lpMaximumComponentLength As Long, lpFileSystemFlags As Long, ByVal lpFileSystemNameBuffer As String, ByVal nFileSystemNameSize As Long) As Long
dim ReturnValue As Long, HDSN, MaxLen As Long, SysFlag As Long, VolName As String, fSysName As String
private sub commadn1_click()
ReturnValue = MymachineC("C:\", VolName, 256, HDSN, MaxLen, SysFlag, fSysName, 256)
msgbox hdsn,,"硬碟序列號"
end sub
Ⅵ VB如何獲取機器碼(硬碟碼、主板碼等)
'引用api獲得硬碟序列號
Private Declare Function MymachineC Lib "kernel32" Alias "GetVolumeInformationA" (ByVal lpRootPathName As String, ByVal lpVolumeNameBuffer As String, ByVal nVolumeNameSize As Long, lpVolumeSerialNumber As Long, lpMaximumComponentLength As Long, lpFileSystemFlags As Long, ByVal lpFileSystemNameBuffer As String, ByVal nFileSystemNameSize As Long) As Long
Private Sub Form_Load()
Dim AA, 硬碟序列號, Maxlen, Sysflag As Long: Dim VolName, FsysName As String
AA = MymachineC("c:\", VolName, 256, 硬碟序列號, Maxlen, Sysflag, FsysName, 256)
msgbox "C硬碟序列號-機器碼啦-(16制): " & Hex(硬碟序列號)
End Sub
這樣就搞定了
Ⅶ vb如何讀取硬碟序列號丶總容量
Private Declare Function GetLogicalDriveStrings Lib "kernel32" Alias _
"GetLogicalDriveStringsA" (ByVal nBufferLength As Long, _
ByVal lpBuffer As String) As Long
取得當前所有盤符
Private Declare Function GetDriveType Lib "kernel32" Alias "GetDriveTypeA" _
(ByVal nDrive As String) As Long
判斷盤符類型
Private Declare Function GetDiskFreeSpace Lib "kernel32" Alias "GetDiskFreeSpaceA" (ByVal lpRootPathName As String, lpSectorsPerCluster As Long, lpBytesPerSector As Long, lpNumberOfFreeClusters As Long, lpTtoalNumberOfClusters As Long) As Long
這個或者下面函數取得磁碟信息
Private Declare Function GetDiskFreeSpaceEx Lib "kernel32.dll" Alias "GetDiskFreeSpaceExA" (ByVal lpDirectoryName As String, ByRef lpFreeBytesAvailableToCaller As ULARGE_INTEGER, ByRef lpTotalNumberOfBytes As ULARGE_INTEGER, ByRef lpTotalNumberOfFreeBytes As ULARGE_INTEGER) As Long
Ⅷ vb6怎樣讀取win10下硬碟序列號
vb6讀取win10下硬碟序列號方法如下:
1、是指硬碟物理序列號,格式化沒有變化。
2、支持vista 及win10系統。
3、支持多塊硬碟(有的電腦裝有幾塊硬碟)
4、支持串口及並口硬碟。
5、最好是源碼或dll 等,代碼如下:
Visual Basic code
'-------------------添加類模塊clsMainInfo-------------------------
Option Explicit
Private Const VER_PLATFORM_WIN32S = 0
Private Const VER_PLATFORM_WIN32_WINDOWS = 1
Private Const VER_PLATFORM_WIN32_NT = 2
Private Const DFP_RECEIVE_DRIVE_DATA = &H7C088
Private Const FILE_SHARE_READ = &H1
Private Const FILE_SHARE_WRITE = &H2
Private Const GENERIC_READ = &H80000000
Private Const GENERIC_WRITE = &H40000000
Private Const OPEN_EXISTING = 3
Private Const Create_NEW = 1
Private Enum HDINFO
HD_MODEL_NUMBER
HD_SERIAL_NUMBER
HD_FIRMWARE_REVISION
End Enum
Private Type OSVERSIONINFO
dwOSVersionInfoSize As Long
dwMajorVersion As Long
dwMinorVersion As Long
dwBuildNumber As Long
dwPlatformId As Long
szCSDVersion As String * 128
End Type
Private Type IDEREGS
bFeaturesReg As Byte
bSectorCountReg As Byte
bSectorNumberReg As Byte
bCylLowReg As Byte
bCylHighReg As Byte
bDriveHeadReg As Byte
bCommandReg As Byte
bReserved As Byte
End Type
Private Type SENDCMDINPARAMS
cBufferSize As Long
irDriveRegs As IDEREGS
bDriveNumber As Byte
bReserved(1 To 3) As Byte
dwReserved(1 To 4) As Long
End Type
Private Type DRIVERSTATUS
bDriveError As Byte
bIDEStatus As Byte
bReserved(1 To 2) As Byte
dwReserved(1 To 2) As Long
End Type
Private Type SENDCMDOUTPARAMS
cBufferSize As Long
DStatus As DRIVERSTATUS
bBuffer(1 To 512) As Byte
End Type
Private Declare Function GetVersionEx _
Lib "kernel32" Alias "GetVersionExA" _
(lpVersionInformation As OSVERSIONINFO) As Long
Private Declare Function CreateFile _
Lib "kernel32" Alias "CreateFileA" _
(ByVal lpFileName As String, _
ByVal dwDesiredAccess As Long, _
ByVal dwShareMode As Long, _
ByVal lpSecurityAttributes As Long, _
ByVal dwCreationDisposition As Long, _
ByVal dwFlagsAndAttributes As Long, _
ByVal hTemplateFile As Long) As Long
Private Declare Function CloseHandle _
Lib "kernel32" _
(ByVal hObject As Long) As Long
Private Declare Function DeviceIoControl _
Lib "kernel32" _
(ByVal hDevice As Long, _
ByVal dwIoControlCode As Long, _
lpInBuffer As Any, _
ByVal nInBufferSize As Long, _
lpOutBuffer As Any, _
ByVal nOutBufferSize As Long, _
lpBytesReturned As Long, _
ByVal lpOverlapped As Long) As Long
Private Declare Sub ZeroMemory _
Lib "kernel32" Alias "RtlZeroMemory" _
(dest As Any, _
ByVal numBytes As Long)
Private Declare Sub CopyMemory _
Lib "kernel32" Alias "RtlMoveMemory" _
(Destination As Any, _
Source As Any, _
ByVal Length As Long)
Private Declare Function GetLastError _
Lib "kernel32" () As Long
Private mvarCurrentDrive As Byte
Private mvarPlatform As String
Public Function GetModelNumber() As String
GetModelNumber = CmnGetHDData(HD_MODEL_NUMBER)
End Function
Public Function GetSerialNumber() As String
GetSerialNumber = CmnGetHDData(HD_SERIAL_NUMBER)
End Function
Public Function GetFirmwareRevision() As String
GetFirmwareRevision = CmnGetHDData(HD_FIRMWARE_REVISION)
End Function
Public Property Let CurrentDrive(ByVal vData As Byte)
If vData < 0 Or vData > 3 Then
Err.Raise 10000, , "Illegal Drive Number"
End If
mvarCurrentDrive = vData
End Property
Public Property Get CurrentDrive() As Byte
CurrentDrive = mvarCurrentDrive
End Property
Public Property Get Platform() As String
Platform = mvarPlatform
End Property
Private Sub Class_Initialize()
Dim OS As OSVERSIONINFO
OS.dwOSVersionInfoSize = Len(OS)
Call GetVersionEx(OS)
mvarPlatform = "Unk"
Select Case OS.dwPlatformId
Case Is = VER_PLATFORM_WIN32S
mvarPlatform = "32S"
Case Is = VER_PLATFORM_WIN32_WINDOWS
If OS.dwMinorVersion = 0 Then
mvarPlatform = "W95"
Else
mvarPlatform = "W98"
End If
Case Is = VER_PLATFORM_WIN32_NT
mvarPlatform = "WNT"
End Select
End Sub
Private Function CmnGetHDData(hdi As HDINFO) As String
Dim bin As SENDCMDINPARAMS
Dim bout As SENDCMDOUTPARAMS
Dim hdh As Long
Dim br As Long
Dim ix As Long
Dim hddfr As Long
Dim hddln As Long
Dim s As String
Select Case hdi
Case HD_MODEL_NUMBER
hddfr = 55
hddln = 40
Case HD_SERIAL_NUMBER
hddfr = 21
hddln = 20
Case HD_FIRMWARE_REVISION
hddfr = 47
hddln = 8
Case Else
Err.Raise 10001, "Illegal HD Data type"
End Select
Select Case mvarPlatform
Case "WNT"
hdh = CreateFile("\.PhysicalDrive" & mvarCurrentDrive, GENERIC_READ + GENERIC_WRITE, FILE_SHARE_READ + FILE_SHARE_WRITE, 0, OPEN_EXISTING, 0, 0)
Case "W95", "W98"
hdh = CreateFile("\.Smartvsd", 0, 0, 0, Create_NEW, 0, 0)
Case Else
Err.Raise 10002, , "Illegal platform (only WNT, W98 or W95)"
End Select
If hdh = 0 Then
Err.Raise 10003, , "Error on CreateFile"
End If
ZeroMemory bin, Len(bin)
ZeroMemory bout, Len(bout)
With bin
.bDriveNumber = mvarCurrentDrive
.cBufferSize = 512
With .irDriveRegs
If (mvarCurrentDrive And 1) Then
.bDriveHeadReg = &HB0
Else
.bDriveHeadReg = &HA0
End If
.bCommandReg = &HEC
.bSectorCountReg = 1
.bSectorNumberReg = 1
End With
End With
DeviceIoControl hdh, DFP_RECEIVE_DRIVE_DATA, bin, Len(bin), bout, Len(bout), br, 0
s = vbNullString
For ix = hddfr To hddfr + hddln - 1 Step 2
If bout.bBuffer(ix + 1) = 0 Then Exit For
s = s & Chr(bout.bBuffer(ix + 1))
If bout.bBuffer(ix) = 0 Then Exit For
s = s & Chr(bout.bBuffer(ix))
Next ix
CloseHandle hdh
CmnGetHDData = Trim(s)
End Function
Visual Basic code
Option Explicit
'純vb的獲取硬碟序列號代碼 (摘自枕善居)
'窗體放置1個ComBox,命名為cbDrive,1個ListBox,命名為lstMain,一個CommandButton,命名為cmdGo,添加如下代碼
Dim h As clsMainInfo
Private Sub cmdGo_Click()
Dim hT As Long
Dim uW() As Byte
Dim dW() As Byte
Dim pW() As Byte
Set h = New clsMainInfo
With h
.CurrentDrive = Val(cbDrive.Text)
lstMain.Clear
lstMain.AddItem "當前驅動器: " & .CurrentDrive
lstMain.AddItem ""
lstMain.AddItem "硬碟型號: " & .GetModelNumber
lstMain.AddItem "序列號: " & .GetSerialNumber
lstMain.AddItem "固件版本: " & .GetFirmwareRevision
End With
Set h = Nothing
End Sub
Private Sub Form_Load()
cbDrive.AddItem 0
cbDrive.AddItem 1
cbDrive.AddItem 2
cbDrive.AddItem 3
cbDrive.ListIndex = 0
End Sub
Ⅸ VB中如何編程獲取硬碟的ID
Private Declare Function hardisk Lib "kernel32" Alias "GetVolumeInformationA" (ByVal lpRootPathName As String, ByVal lpVolumeNameBuffer As String, ByVal nVolumeNameSize As Long, lpVolumeSerialNumber As Long, lpMaximumComponentLength As Long, lpFileSystemFlags As Long, ByVal lpFileSystemNameBuffer As String, ByVal nFileSystemNameSize As Long) As Long
Private Sub Form_Load()
On Error GoTo Err_Form_Load
Dim aa As Long
Dim VolName As String
Dim disnun As Long
Dim Maxlen As Long
Dim Sysflag As Long
Dim fsysName As String
aa = hardisk("c:\", VolName, 256, disnun, Maxlen, Sysflag, fsysName, 256)
MsgBox "c 硬碟序列號(16制): " & Hex(disnun)
Exit Sub
Err_Form_Load:
End Sub
Ⅹ vb中怎樣獲得硬碟序列號
上面的硬碟序列號都是邏輯盤序列號
每次格式化時都會改變而且很容易更改
你需要的應是物理序列號,是硬碟出廠時固化的
全球唯一的十位字元
網上有人編好的getdiskinfo
好像vsit不能用
或用WMI:Win32_PhysicalMedia
不過用在vsit里得出的是20位的16進制字元串
你要設法檢測與轉換
我現在是把多種方法組合起來用
WMI功能比較強但初始化比較慢
我還用匯編試過,快不過不太穩定
常式我就不提供了,自己去搜索一下。