|
使用Windows API读硬盘序列号,根据序列号生成注册码,就可以保证注册码唯一。
读硬盘序列号的源程序如下:
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
Function dhPrintVolInfo(Optional strDrive As String = vbNullString)
' Sample procedure demonstrating GetVolumeInformation API function.
' From "VBA Developer's Handbook"
' by Ken Getz and Mike Gilbert
' Copyright 1997; Sybex, Inc. All rights reserved.
' In:
' strDrive (Optional, default = vbNullString)
' String representing root directory of a drive
' (e.g. "C:\") or empty string for current drive.
' Out:
' Return Value:
' n/a
' Example:
' Call dhPrintVolInfo
Dim strVolLabel As String
Dim strFileSystem As String
Dim lngVolumeSerialNumber As Long
Dim lngMaximumComponentLength As Long
Dim lngFileSystemFlags As Long
' Set up the buffers
strVolLabel = Space(255)
strFileSystem = Space(255)
' Call GetVolumeInformation
If CBool(GetVolumeInformation(strDrive, _
strVolLabel, Len(strVolLabel), _
lngVolumeSerialNumber, _
lngMaximumComponentLength, _
lngFileSystemFlags, _
strFileSystem, Len(strFileSystem))) Then
' Parse buffers
strVolLabel = dhTrimNull(strVolLabel)
strFileSystem = dhTrimNull(strFileSystem)
' Print information
' Debug.Print strDrive, _
' strVolLabel, _
' Hex(lngVolumeSerialNumber), _
' lngMaximumComponentLength
dhPrintVolInfo = Hex(lngVolumeSerialNumber)
End If
End Function
如果要获取C:\序列号,可这样调用:
dim snC
snC=dhPrintVolInfo("C:\")
|
|