你这个帖子白发了,不会有答案的。
内嵌汇编一般是很难的,根本不实用。或者,我用VC写个EXE,然后在Basic里调用可以吗?不过到头来VC程序还要用GetVolumeInformation …… 呵呵
内嵌汇编一般是很难的,根本不实用。或者,我用VC写个EXE,然后在Basic里调用可以吗?不过到头来VC程序还要用GetVolumeInformation …… 呵呵
解决方案 »
- vb字符串中双字节字符转换为单字节字符的疑问?
- JET SQL能同时操作mdb和excel两个表吗?
- 如何根据hWnd得到对像的引用? 如何根据对像名得到对像的引用? VB消息处理的机制?
- 解方程
- 昨天关机的时候不小心碰了电源插坐,今天开机显示win2000启动画面以后就蓝屏
- vb中文本框内容显示问题
- 好久没有来了,CSDN 怎么多了一些无聊的人。好在我并不在乎他们的存在。
- 怎样转换字符串!!!!!!!!!中英文混合文本实现跑马灯存在的问题??
- 关于NULL,请多多关照
- 使用VBA网抓智联招聘的数据
- 有谁知道用outlook或foxmail发邮件时,主题或附件名为中文时是怎么编码的?
- 急!急!急!急!100分!100分!100分!100分!100分!
Sub ShowDriveList()
On Error Resume Next
Dim fs
Dim s As String
Dim a As Scripting.Drive
Set fs = CreateObject("Scripting.FileSystemObject")
For Each a In fs.Drives
s = s & a.DriveLetter & " - " & a.SerialNumber & vbCrLf
Next
MsgBox s
End Sub
=============================================================
Private mRootName As String
Private lpVolumeNameBuffer As String
Private nVolumeNameSize As Long
Private lpVolumeSerialNumber As Long
Private lpMaximumComponentLength As Long
Private lpFileSystemFlags As Long
Private lpFileSystemNameBuffer As String
Private nFileSystemNameSize As Long'\\ API call declarations...
Private 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 LongPrivate Declare Function SetVolumeLabel Lib "kernel32" _
Alias "SetVolumeLabelA" (ByVal lpRootPathName As String, _
ByVal lpVolumeName As String) As Long
Public Enum FileSystemFlags
FILE_CASE_SENSITIVE_SEARCH = &H1
FILE_CASE_PRESERVED_NAMES = &H2
FILE_UNICODE_ON_DISK = &H4
FILE_PERSISTENT_ACLS = &H8
FILE_FILE_COMPRESSION = &H10
FILE_VOLUME_QUOTAS = &H20
FILE_SUPPORTS_SPARSE_FILES = &H40
FILE_SUPPORTS_REPARSE_POINTS = &H80
FILE_SUPPORTS_REMOTE_STORAGE = &H100
FILE_VOLUME_IS_COMPRESSED = &H8000
FILE_SUPPORTS_OBJECT_IDS = &H10000
FILE_SUPPORTS_ENCRYPTION = &H20000
End EnumPrivate bChanged As Boolean
Friend Property Get Changed() As Boolean
Changed = bChanged
End Property
Friend Property Let Changed(ByVal newChanged As Boolean)
bChanged = newChanged
End PropertyPublic Property Get CasePreserved() As BooleanCall RefreshVolumeInfo
CasePreserved = (lpFileSystemFlags And FILE_CASE_PRESERVED_NAMES)End PropertyPublic Property Get CaseSensitive() As BooleanCall RefreshVolumeInfo
CaseSensitive = (lpFileSystemFlags And FILE_CASE_SENSITIVE_SEARCH)End Property
Public Property Get Compressed() As BooleanCall RefreshVolumeInfo
Compressed = (lpFileSystemFlags And FILE_VOLUME_IS_COMPRESSED)End PropertyPublic Property Get Encryption() As BooleanCall RefreshVolumeInfo
Encryption = (lpFileSystemFlags And FILE_SUPPORTS_ENCRYPTION)End PropertyPublic Property Get FileCompression() As BooleanCall RefreshVolumeInfo
FileCompression = (lpFileSystemFlags And FILE_FILE_COMPRESSION)End PropertyPublic Property Get FileSystemName() As StringCall RefreshVolumeInfo
If InStr(lpFileSystemNameBuffer, Chr$(0)) > 0 Then
FileSystemName = Left$(lpFileSystemNameBuffer, InStr(lpFileSystemNameBuffer, Chr$(0)) - 1)
End IfEnd PropertyPublic Property Get ObjectIds() As BooleanCall RefreshVolumeInfo
ObjectIds = (lpFileSystemFlags And FILE_SUPPORTS_OBJECT_IDS)End PropertyPublic Property Get PersistantACLs() As BooleanCall RefreshVolumeInfo
PersistantACLs = (lpFileSystemFlags And FILE_PERSISTENT_ACLS)End PropertyPrivate Sub RefreshVolumeInfo()Dim lret As Long'\\ Initialise the buffers
lpVolumeNameBuffer = String$(1024, 0)
nVolumeNameSize = Len(lpVolumeNameBuffer)
lpFileSystemNameBuffer = String$(1024, 0)
nFileSystemNameSize = Len(lpFileSystemNameBuffer)
lret = GetVolumeInformation(mRootName, lpVolumeNameBuffer, nVolumeNameSize, lpVolumeSerialNumber, lpMaximumComponentLength, lpFileSystemFlags, lpFileSystemNameBuffer, nFileSystemNameSize)
If Err.LastDllError <> 0 Then
ReportError Err.LastDllError, "ApiVolume:Name (Let)", GetLastSystemError
End IfEnd SubPublic Property Get RemoteStorage() As BooleanCall RefreshVolumeInfo
RemoteStorage = (lpFileSystemFlags And FILE_SUPPORTS_REMOTE_STORAGE)End PropertyPublic Property Get ReparsePoints() As BooleanCall RefreshVolumeInfo
ReparsePoints = (lpFileSystemFlags And FILE_SUPPORTS_REPARSE_POINTS)End PropertyPublic Property Get RootName() As StringRootName = mRootNameEnd PropertyPublic Property Let RootName(ByVal newname As String)Dim lret As Long'\\ If the name changes get all the other volume info...
If newname <> mRootName Then
mRootName = newname
End IfEnd PropertyPublic Property Get SerialNumber() As LongCall RefreshVolumeInfo
SerialNumber = lpVolumeSerialNumberEnd PropertyPublic Property Get SparseFiles() As BooleanCall RefreshVolumeInfo
SparseFiles = (lpFileSystemFlags And FILE_SUPPORTS_SPARSE_FILES)End PropertyPublic Property Get UnicodeFileTable() As BooleanCall RefreshVolumeInfo
UnicodeFileTable = (lpFileSystemFlags And FILE_UNICODE_ON_DISK)End PropertyPublic Property Let VolumeName(ByVal newname As String)Dim lret As Longlret = SetVolumeLabel(mRootName, newname)
If Err.LastDllError Then
ReportError Err.LastDllError, "ApiVolume:Volumename (Let)", GetLastSystemError
End IfEnd PropertyPublic Property Get VolumeName() As StringCall RefreshVolumeInfo
If InStr(lpVolumeNameBuffer, Chr$(0)) > 0 Then
VolumeName = Left$(lpVolumeNameBuffer, InStr(lpVolumeNameBuffer, Chr$(0)) - 1)
End IfEnd Property
Public Property Get VolumeQuotas() As BooleanCall RefreshVolumeInfo
VolumeQuotas = (lpFileSystemFlags And FILE_VOLUME_QUOTAS)End Property
搞定!看代码!
Sub ShowDriveList()
On Error Resume Next
Dim fs
Dim s As String
Dim a As Scripting.Drive
Set fs = CreateObject("Scripting.FileSystemObject")For Each a In fs.Drives
s = s & a.DriveLetter & " - " & a.SerialNumber & vbCrLf
Next
MsgBox s
End Sub补充:需要引用Script库,否则要改代码:
Sub ShowDriveList()
On Error Resume Next
Dim fs
Dim s As String
Dim a
Set fs = CreateObject("Scripting.FileSystemObject")For Each a In fs.Drives
s = s & a.DriveLetter & " - " & a.SerialNumber & vbCrLf
Next
MsgBox s
End Sub
自己写个驱动挂上。就象HWiNFO一样,就知道了。其他没办法
磁盘序列号,每次格式化后生成,而且绝不重复,可以用来加密.在vb中我是这样获取它的:
在窗体上放一个label放一个command
然后粘上这一段代码,就可以获得d:盘的序列号:
Private Declare Function GetVolumeInformation Lib "kernel32.dll" Alias "GetVolumeInformationA" (ByVal lpRootPathName As String, ByVal lpVolumeNameBuffer As String, ByVal nVolumeNameSize As Integer, lpVolumeSerialNumber As Long, lpMaximumComponentLength As Long, lpFileSystemFlags As Long, ByVal lpFileSystemNameBuffer As String, ByVal nFileSystemNameSize As Long) As Long
Function GetSerialNumber(sRoot As String) As Long
Dim lSerialNum As Long
Dim R As Long
Dim sTemp1 As String, sTemp2 As String
strLabel = String$(255, Chr$(0))
strType = String$(255, Chr$(0))
R = GetVolumeInformation(sRoot, strLabel, Len(strLabel), lSerialNum, 0, 0, strType, Len(strType))
GetSerialNumber = lSerialNum
End Function
Private Sub Command1_Click()
i = GetSerialNumber("d:\")
Label1.Caption = "序列号为" + CStr(i)
End Sub
我有用VC做的DLL解决方法,可有时候系统太忙时不能正确读取物理序列号。