如何使用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. WMI HDD序列号转换
- 3. 使用终端在OSx上获得主HDD序列号
- 4. 如何检索.net中的HDD固件序列号?
- 5. 如何使用C#从移动设备读取序列号?
- 6. 如何读取txt文件中的特定行vb 6
- 7. 保留卷序列号
- 8. 如何获取系统驱动器卷序列号
- 9. 如何使用VB获取文本文件的DateTime标记6
- 10. 读取和使用序列
- 11. 获取IDE和SATA的H/D序列号(不是卷序列号)
- 12. 网页读取序列号GUID
- 13. 如何使用星号读取DTMF
- 14. C#/ Native:使用SCSI PassThrough读取HDD串行
- 15. 读取USB设备序列号在C#
- 16. 使用VB脚本读取xml节点
- 17. 如何使用RFID阅读器获取RFID标签上打印的序列号?
- 18. 如何挑选/读取使用VB 6.0 ADO
- 19. 如何使用jet引擎从excel中读取数据vb
- 20. 使用javax.smartcardio从智能卡读取序列号
- 21. 使用openssl从x509 certiticate读取序列号(ASN1_INTEGER)失败
- 22. 使用WinSCard获取PCSC读卡器序列号
- 23. VB 6应用程序的国际化
- 24. 如何使用VB将表转换为列使用VB
- 25. 如何从表中读取数据并分配序列号?
- 26. 如何从VB 6应用程序中确定Windows版本?
- 27. 如何在vb 6中使用dll制作c#.net 3.5应用程序?
- 28. 我怎样才能使用wxWidgets卷序列号?
- 29. 如何序列化VB中的列表?
- 30. Vb 6 listview substring_index
Thanx @ C-Pound Guru –
完美的答案! – indago