取硬盘ID:
1、声明API:
Function Boolean GetVolumeInformationA(ref String ls_Rootpath, ref String ls_volumnename,Ulong lul_VolumeNameSize, ref Ulong lul_VolumeSerialNumber,ref Ulong lul_MaximumComponentLength,ref Ulong lul_FileSystemFlags,ref String ls_FileSystemNameBuffer,Ulong lul_FileSystemNameSize) Library "Kernel32.dll "
2、如下代码实现取硬盘ID:
String ls_Rootpath, ls_volumnename
ls_Rootpath = "C: " // 指定要得到序列号的硬盘,
// 一般情况都是C盘,除非你能保证用户存在其它逻辑盘或物理盘
ls_volumnename = Space(256) // 分配足够的空间,下同
Ulong lul_VolumeNameSize
lul_VolumeNameSize = 256
Ulong lul_VolumeSerialNumber, lul_MaximumComponentLength, lul_FileSystemFlags
lul_MaximumComponentLength = 256
String ls_FileSystemNameBuffer
ls_FileSystemNameBuffer = space(256)
Ulong lul_FileSystemNameSize
lul_FileSystemNameSize = 256
beep(1)
boolean lb_rtn
lb_rtn = False
lb_rtn = GetVolumeInformationA(ls_Rootpath, ls_volumnename, lul_VolumeNameSize, lul_VolumeSerialNumber, lul_MaximumComponentLength, lul_FileSystemFlags, ls_FileSystemNameBuffer, lul_FileSystemNameSize)
if lb_rtn = true then
MessageBox( "提示 ", "函数调用成功! ")
else
MessageBox( "提示 ", "函数调用失败! ")
end if
sle_1.text = String(lul_VolumeSerialNumber) // 得到硬盘序列号
PB9 测试通过。
另,MAC、CUPID等可参考其它API。