如何使用VB 6讀取HDD卷序列號,但不使用任何ActiveX控件或第三方加載項?如何使用VB 6讀取HDD卷序列號?
2
A
回答
5
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) As Long
Public Function GetSerialNumber(_
ByVal sDrive As String) As Long
If Len(sDrive) Then
If InStr(sDrive, "\\") = 1 Then
' Make sure we end in backslash for UNC
If Right$(sDrive, 1) <> "\" Then
sDrive = sDrive & "\"
End If
Else
' If not UNC, take first letter as drive
sDrive = Left$(sDrive, 1) & ":\"
End If
Else
' Else just use current drive
sDrive = vbNullString
End If
' Grab S/N -- Most params can be NULL
Call GetVolumeInformation(_
sDrive, vbNullString, 0, GetSerialNumber, _
ByVal 0&, ByVal 0&, vbNullString, 0)
End Function
要撥打:
Dim Drive As String
Drive = InputBox("Enter drive for checking SN")
MsgBox Hex$(GetSerialNumber(Drive))
1
下面的示例提供了驅動器的串行您的EXE是
'APi declaration
Declare Function GetVolumeInformation 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
Sub subHDsn()
Dim TempAPi, VolumeSerial As Long
Dim strPATH As String
On Error Resume Next
TempAPi = 0
VolumeSerial = 0
If App.Path Like "*:*" Then
'checking whether the drive is local or mapped
strPATH = Left(App.Path, 3)
Else
'if it's a UNC
strPATH = Left(App.Path, InStr((InStr(3, App.Path, "\") + 1), App.Path, "\"))
End If
'call API
TempAPi = GetVolumeInformation(strPATH, VolumeName, 100, VolumeSerial, 100, FileSystemFlags, FileSystemName, 100)
If TempAPi = 0 Then
MsgBox "Error calling API!", 16
End
End If
'convert from HeX
HDsn = Hex(VolumeSerial)
End Sub
1
下面的示例無需API。
Public Function GetSerialNumber(ByVal sDrive As String) As String
On Error Resume Next
Open "Vol.bat" For Output As 1
Print #1, "@vol %1%>DSN"
Close
Kill "DSN"
Shell ("Vol.bat " + sDrive)
Do
Open "DSN" For Input As 1
Input #1, GetSerialNumber
Input #1, GetSerialNumber
Close
Loop While GetSerialNumber = ""
GetSerialNumber = Right$(GetSerialNumber, 9)
Kill "Vol.bat"
Kill "DSN"
End Function
相關問題
- 1. 使用asp.net獲取HDD序列號?
- 2. 在Swift中獲取HDD序列號
- 3. WMI HDD序列號轉換
- 4. 使用終端在OSx上獲得主HDD序列號
- 5. 如何檢索.net中的HDD固件序列號?
- 6. 如何使用C#從移動設備讀取序列號?
- 7. 如何獲得卷序列號
- 8. 如何從vb 6中逐行讀取文本文件內容?
- 9. 如何讀取txt文件中的特定行vb 6
- 10. 如何在VB 6
- 11. 如何使用序列化讀取char *
- 12. 保留卷序列號
- 13. 如何獲取系統驅動器卷序列號
- 14. 如何使用VB獲取文本文件的DateTime標記6
- 15. 如何閱讀HDD S.M.A.R.T.屬性?
- 16. 讀取和使用序列
- 17. 獲取IDE和SATA的H/D序列號(不是卷序列號)
- 18. 網頁讀取序列號GUID
- 19. 如何使用星號讀取DTMF
- 20. C#/ Native:使用SCSI PassThrough讀取HDD串行
- 21. 如何讀取和更改SSIS列中的序列號?
- 22. 如何查找LTFS卷序列號而不是磁帶驅動器序列號
- 23. 讀取USB設備序列號在C#
- 24. VB - 使用XPath讀取XML的問題
- 25. 使用VB腳本讀取xml節點
- 26. 如何使用RFID閱讀器獲取RFID標籤上打印的序列號?
- 27. 如何使用jet引擎從excel中讀取數據vb
- 28. 如何挑選/讀取使用VB 6.0 ADO
- 29. VB 6應用程序的國際化
- 30. 使用javax.smartcardio從智能卡讀取序列號
Thanx @ C-Pound Guru –
完美的答案! – indago