获取硬盘序列号代码

152 views 四月 29, 05 by Timothy

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!”);
}

分享到:

声明: 此Blog中的文章和随笔仅代表作者在某一特定时间内的观点和结论,对其完全的正确不做任何担保或假设
本站文章均采用 知识共享署名-相同方式共享3.0 协议进行授权,除非注明,本站文章均为原创,转载请注明转自 Timothy's Space 并应以链接形式标明本文地址!

你可能也对下列文章感兴趣

  • 没有相关文章!

Add your comment

1 Responses to "获取硬盘序列号代码"

  1. snz273 CHINA 说道:

    支持。


Leave a Reply

 您已输入0

(Ctrl+Enter)