用这个API:GetVolumeInformation,具体自己找找MSDN吧。
解决方案 »
- ^_^ 给力,找了好久,终让我找到了,好多VB源码免费下载,路过的朋友快看看吧
- 要对EMSG.lParamLow进行如何处理才能得到键值??
- 怎样用代码定义一个控件数组?急
- 请问各位大侠,怎么样才能把日文的字符序列转换成16进制的数据序列?
- 我想用程序下载一些文本文件,谁能写个源代码??
- 如何在字符串里带引号?
- 请问哪位或哪里有IBM ViaVoice SDK for Windows??(有卖(便宜的哟),有下载都行)谢谢!!
- ERP源程序出售(价格优惠)
- 怎样实现象窗体缩小到任务栏时,窗体由大到小移动到指定方向的动态效果。我想使我的程序在缩小为一个工具条时显示这样的效果。
- 谢谢各位,在vb开发com时,如何定义接口,书上写的class builder我没找到,谢了
- 我能挣多少?????( in 北京)------------北京的大虾们救救命!(散分!散分!再散分!)
- 如何取得硬件的唯一序列号?
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
说明
获取与一个磁盘卷有关的信息
返回值
Long,非零表示成功,零表示失败。会设置GetLastError
参数表
参数 类型及说明
lpRootPathName String,欲获取信息的那个卷的根路径
lpVolumeNameBuffer String,用于装载卷名(卷标)的一个字串
nVolumeNameSize Long,lpVolumeNameBuffer字串的长度
lpVolumeSerialNumber Long,用于装载磁盘卷序列号的变量
lpMaximumComponentLength Long,指定一个变量,用于装载文件名每一部分的长度。例如,在“c:\component1\component2.ext”的情况下,它就代表component1或component2名称的长度
lpFileSystemFlags Long,用于装载一个或多个二进制位标志的变量。对这些标志位的解释如下:
FS_CASE_IS_PRESERVED 文件名的大小写记录于文件系统
FS_CASE_SENSITIVE 文件名要区分大小写
FS_UNICODE_STORED_ON_DISK 文件名保存为Unicode格式
FS_PERSISTANT_ACLS 文件系统支持文件的访问控制列表(ACL)安全机制
FS_FILE_COMPRESSION 文件系统支持逐文件的进行文件压缩
FS_VOL_IS_COMPRESSED 整个磁盘卷都是压缩的
lpFileSystemNameBuffer String,指定一个缓冲区,用于装载文件系统的名称(如FAT,NTFS以及其他)
nFileSystemNameSize Long,lpFileSystemNameBuffer字串的长度
text1.text=getval
Dim root As String
Dim volume_name As String
Dim serial_number As Long
Dim max_component_length As Long
Dim file_system_flags As Long
Dim file_system_name As String
Dim pos As Integer root = Text1.Text
volume_name = Space$(1024)
file_system_name = Space$(1024) If GetVolumeInformation(root, volume_name, _
Len(volume_name), serial_number, _
max_component_length, file_system_flags, _
file_system_name, Len(file_system_name)) = 0 _
Then
MsgBox "Error getting volume information."
Exit Sub
End If pos = InStr(volume_name, Chr$(0))
volume_name = Left$(volume_name, pos - 1)
lblVolumeName.Caption = volume_name lblSerialNumber.Caption = Format$(serial_number) lblMaxComponentLength.Caption = Format$(max_component_length) pos = InStr(file_system_name, Chr$(0))
file_system_name = Left$(file_system_name, pos - 1)
lblFileSystem.Caption = file_system_name lblFlags.Caption = "&&H" & Hex$(file_system_flags)
End Sub
http://ygyuan.3322.net/
下载并安装"雁留声名录系统",然后你就可以得到第一个硬盘的序列号了!Private Declare Function GetDiskSN Lib "GetDiskSN.dll" (ByVal lpszSN As String) As DoubleDim s As String
s = String(1024, Chr(0))
GetDiskSN (s)
s = Trim(Replace(s, Chr(0), ""))
msgbox s
'you will get two different serail number for the two drives.
'It seems as if logical drives get their own serial number...
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 Long
Private Sub Form_Load()
'KPD-Team 1998
'URL: http://www.allapi.net/
'E-Mail: [email protected]
Dim Serial As Long, VName As String, FSName As String
'Create buffers
VName = String$(255, Chr$(0))
FSName = String$(255, Chr$(0))
'get the volume information
GetVolumeInformation "C:\", VName, 255, Serial, 0, 0, FSName, 255
'Strip the extra chr$(0)'s
VName = Left$(VName, InStr(1, VName, Chr$(0)) - 1)
FSName = Left$(FSName, InStr(1, FSName, Chr$(0)) - 1)
MsgBox "The Volume name of C:\ is '" + VName + "', the File system name of C:\ is '" + FSName + "' and the serial number of C:\ is '" + Trim(Str$(Serial)) + "'", vbInformation + vbOKOnly, App.Title
End Sub
在窗体上放一个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