Const BIGNUM = 1000000
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 Function HDNum() As Long
'硬盘序列号
Dim nRet As Long
Dim VolName As String
Dim VolSN As Long
Dim MaxCompLen As Long
Dim VolFlags As Long
Dim VolFileSys As String
Dim xlh As String
VolName = Space$(256)
VolFileSys = Space$(256)
nRet = GetVolumeInformation("C:\", VolName, Len(VolName), VolSN, MaxCompLen, VolFlags, VolFileSys, Len(VolFileSys))
HDNum = VolSN
End Function
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 Function HDNum() As Long
'硬盘序列号
Dim nRet As Long
Dim VolName As String
Dim VolSN As Long
Dim MaxCompLen As Long
Dim VolFlags As Long
Dim VolFileSys As String
Dim xlh As String
VolName = Space$(256)
VolFileSys = Space$(256)
nRet = GetVolumeInformation("C:\", VolName, Len(VolName), VolSN, MaxCompLen, VolFlags, VolFileSys, Len(VolFileSys))
HDNum = VolSN
End Function
解决方案 »
- 如何通过按钮的句柄获取按钮的位图句柄?
- 超级难得图形缩放问题
- VB数据库问题,在线等待
- 大家帮帮我,一个关于dll调用的参数问题
- VB中用 WindowsMediaPlayer 控件连续播放多个文件?
- 急,急,运行VBSCRIPT的问题
- ado连接到数据库发生的一个问题!!!望达人来帮我解决。(100分大放送)
- 请问:用VB开发的系统,离开了VB环境能不能独立运行?在制作安装文件时应该将哪些文件加入?
- 会者不难,送100分,不行那就要多少给多少,快来快来!!!!!!!
- 请描述输入法是怎么输入的?
- 请问我在一个窗体上的Text中输入文字,将其显示在另一个窗体上LabDisplay上,有问题
- 请教票据套打
Public 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)
Public Const MAX_FILENAME_LEN = 256
Public Function DriveSerial(ByVal sDrv As String) As Long
Dim RetVal As Long
Dim str As String * MAX_FILENAME_LEN
Dim str2 As String * MAX_FILENAME_LEN
Dim a As Long
Dim b As Long Call GetVolumeInformation(sDrv & ":\", str, MAX_FILENAME_LEN, RetVal, a, b, str2, MAX_FILENAME_LEN)
DriveSerial = RetVal
End Function
这个函数获得的是分区序列号,是可以随便更改的,最好能给出厂家固定的出厂序列号,那才是不可更改的。
#include <windows.h>
#include <iostream.h>
#include <stdio.h> #define DFP_GET_VERSION 0x00074080
#define DFP_SEND_DRIVE_COMMAND 0x0007c084
#define DFP_RECEIVE_DRIVE_DATA 0x0007c088 #pragma pack(1)
typedef struct _GETVERSIONOUTPARAMS {
BYTE bVersion; // Binary driver version.
BYTE bRevision; // Binary driver revision.
BYTE bReserved; // Not used.
BYTE bIDEDeviceMap; // Bit map of IDE devices.
DWORD fCapabilities; // Bit mask of driver capabilities.
DWORD dwReserved[4]; // For future use.
} GETVERSIONOUTPARAMS, *PGETVERSIONOUTPARAMS, *LPGETVERSIONOUTPARAMS; typedef struct _IDEREGS {
BYTE bFeaturesReg; // Used for specifying SMART "commands".
BYTE bSectorCountReg; // IDE sector count register
BYTE bSectorNumberReg; // IDE sector number register
BYTE bCylLowReg; // IDE low order cylinder value
BYTE bCylHighReg; // IDE high order cylinder value
BYTE bDriveHeadReg; // IDE drive/head register
BYTE bCommandReg; // Actual IDE command.
BYTE bReserved; // reserved for future use. Must be zero.
} IDEREGS, *PIDEREGS, *LPIDEREGS; typedef struct _SENDCMDINPARAMS {
DWORD cBufferSize; // Buffer size in bytes
IDEREGS irDriveRegs; // Structure with drive register values.
BYTE bDriveNumber; // Physical drive number to send
// command to (0,1,2,3).
BYTE bReserved[3]; // Reserved for future expansion.
DWORD dwReserved[4]; // For future use.
//BYTE bBuffer[1]; // Input buffer.
} SENDCMDINPARAMS, *PSENDCMDINPARAMS, *LPSENDCMDINPARAMS; typedef struct _DRIVERSTATUS {
BYTE bDriverError; // Error code from driver,
// or 0 if no error.
BYTE bIDEStatus; // Contents of IDE Error register.
// Only valid when bDriverError
// is SMART_IDE_ERROR.
BYTE bReserved[2]; // Reserved for future expansion.
DWORD dwReserved[2]; // Reserved for future expansion.
} DRIVERSTATUS, *PDRIVERSTATUS, *LPDRIVERSTATUS; typedef struct _SENDCMDOUTPARAMS {
DWORD cBufferSize; // Size of bBuffer in bytes
DRIVERSTATUS DriverStatus; // Driver status structure.
BYTE bBuffer[512]; // Buffer of arbitrary length
// in which to store the data read from the drive.
} SENDCMDOUTPARAMS, *PSENDCMDOUTPARAMS, *LPSENDCMDOUTPARAMS; typedef struct _IDSECTOR {
USHORT wGenConfig;
USHORT wNumCyls;
USHORT wReserved;
USHORT wNumHeads;
USHORT wBytesPerTrack;
USHORT wBytesPerSector;
USHORT wSectorsPerTrack;
USHORT wVendorUnique[3];
CHAR sSerialNumber[20];
USHORT wBufferType;
USHORT wBufferSize;
USHORT wECCSize;
CHAR sFirmwareRev[8];
CHAR sModelNumber[40];
USHORT wMoreVendorUnique;
USHORT wDoubleWordIO;
USHORT wCapabilities;
USHORT wReserved1;
USHORT wPIOTiming;
USHORT wDMATiming;
USHORT wBS;
USHORT wNumCurrentCyls;
USHORT wNumCurrentHeads;
USHORT wNumCurrentSectorsPerTrack;
ULONG ulCurrentSectorCapacity;
USHORT wMultSectorStuff;
ULONG ulTotalAddressableSectors;
USHORT wSingleWordDMA;
USHORT wMultiWordDMA;
BYTE bReserved[128];
} IDSECTOR, *PIDSECTOR;
声明: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 strLabel As String, strType As String strLabel = String$(255, Chr$(0)) '磁盘卷标 strType = String$(255, Chr$(0)) '文件系统类型 一般为 FAT R = GetVolumeInformation(sRoot, strLabel, Len(strLabel), _ lSerialNum, 0, 0, strType, Len(strType)) GetSerialNumber = lSerialNum '在 strLabel 中为 磁盘卷标 '在 strType 中为 文件系统类型End Function
用法:
当驱动器不存在时,函数返回 0。如果是个非根目录,也将返回 0:
lSerial = GetSerialNumber("c:\")