获取硬盘序列号代码
void CDrvSrlNmbrDlg::OnGetSrlNum()
{
//更新下拉框的驱动器号
UpdateData(TRUE);
//获得下拉框的指针对象
CComboBox* Driver=(CComboBox*)GetDlgItem(IDC_DRIVER);
//获得当前选择的驱动器
CString strRootPathName;
Driver->GetWindowText(strRootPathName);
//获得驱动器序列号
LPCTSTR lpRootPathName = strRootPathName;
LPTSTR lpVolumeNameBuffer=new char[12];
DWORD nVolumeNameSize=12;
DWORD VolumeSerialNumber;
DWORD MaximumComponentLength;
DWORD FileSystemFlags;
LPTSTR lpFileSystemNameBuffer=new char[10];
DWORD nFileSystemNameSize=10;
GetVolumeInformation(lpRootPathName,
lpVolumeNameBuffer, nVolumeNameSize,
&VolumeSerialNumber,
&MaximumComponentLength,
&FileSystemFlags,
lpFileSystemNameBuffer, nFileSystemNameSize);
//显示驱动器序列号
CString str;
str.Format("驱动器%s的序列号为%x",strRootPathName,VolumeSerialNumber);
AfxMessageBox(str);
}
void CDrvSrlNmbrDlg::FindAllDrivers()
{
CComboBox* Driver=(CComboBox*)GetDlgItem(IDC_DRIVER);
DWORD dwNumBytesForDriveStrings;//实际存储驱动器号的字符串长度
HANDLE hHeap;
LPSTR lp;
CString strLogdrive;
//获得实际存储驱动器号的字符串长度
dwNumBytesForDriveStrings=GetLogicalDriveStrings(0,NULL)*sizeof(TCHAR);
//如果字符串不为空,则表示有正常的驱动器存在
if (dwNumBytesForDriveStrings!=0) {
//分配字符串空间
hHeap=GetProcessHeap();
lp=(LPSTR)HeapAlloc(hHeap,HEAP_ZERO_MEMORY,
dwNumBytesForDriveStrings);
//获得标明所有驱动器的字符串
GetLogicalDriveStrings(HeapSize(hHeap,0,lp),lp);
//将驱动器一个个放到下拉框中
while (*lp!=0) {
Driver->AddString(lp);
lp=_tcschr(lp,0)+1;
}
}
else
AfxMessageBox("Can't Use The Function GetLogicalDriveStrings!");
}
{
//更新下拉框的驱动器号
UpdateData(TRUE);
//获得下拉框的指针对象
CComboBox* Driver=(CComboBox*)GetDlgItem(IDC_DRIVER);
//获得当前选择的驱动器
CString strRootPathName;
Driver->GetWindowText(strRootPathName);
//获得驱动器序列号
LPCTSTR lpRootPathName = strRootPathName;
LPTSTR lpVolumeNameBuffer=new char[12];
DWORD nVolumeNameSize=12;
DWORD VolumeSerialNumber;
DWORD MaximumComponentLength;
DWORD FileSystemFlags;
LPTSTR lpFileSystemNameBuffer=new char[10];
DWORD nFileSystemNameSize=10;
GetVolumeInformation(lpRootPathName,
lpVolumeNameBuffer, nVolumeNameSize,
&VolumeSerialNumber,
&MaximumComponentLength,
&FileSystemFlags,
lpFileSystemNameBuffer, nFileSystemNameSize);
//显示驱动器序列号
CString str;
str.Format("驱动器%s的序列号为%x",strRootPathName,VolumeSerialNumber);
AfxMessageBox(str);
}
void CDrvSrlNmbrDlg::FindAllDrivers()
{
CComboBox* Driver=(CComboBox*)GetDlgItem(IDC_DRIVER);
DWORD dwNumBytesForDriveStrings;//实际存储驱动器号的字符串长度
HANDLE hHeap;
LPSTR lp;
CString strLogdrive;
//获得实际存储驱动器号的字符串长度
dwNumBytesForDriveStrings=GetLogicalDriveStrings(0,NULL)*sizeof(TCHAR);
//如果字符串不为空,则表示有正常的驱动器存在
if (dwNumBytesForDriveStrings!=0) {
//分配字符串空间
hHeap=GetProcessHeap();
lp=(LPSTR)HeapAlloc(hHeap,HEAP_ZERO_MEMORY,
dwNumBytesForDriveStrings);
//获得标明所有驱动器的字符串
GetLogicalDriveStrings(HeapSize(hHeap,0,lp),lp);
//将驱动器一个个放到下拉框中
while (*lp!=0) {
Driver->AddString(lp);
lp=_tcschr(lp,0)+1;
}
}
else
AfxMessageBox("Can't Use The Function GetLogicalDriveStrings!");
}
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· DeepSeek 开源周回顾「GitHub 热点速览」
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了