本文介绍了请谁能告诉我为什么此磁盘序列号检索程序不起作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
#include <windows.h>
#include <iostream>
#include <winioctl.h>
using namespace std;
BOOL GetDiskInfo(CHANGER_PRODUCT_DATA *Data)
{
HANDLE hDevice;
BOOL bResult;
DWORD junk;
hDevice = CreateFile(TEXT("\\\\.\\c:"),
GENERIC_READ,
FILES_HARE_READ|FILE_SHARE_WRITE,
NULL,
OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL);
if(hDevice == INVALID_FILE_VALUE)
{
cout<<could not access disk\n;
return FALSE;
}
bResult = DviceIoControl(hDevice,IOCTL_CHANGER_PRODUCT_DATA,NULL,0,Data,sizeof(*Data),&junk, (LPOVERLAPPED) NULL);
closeHandle(hDevice);
return (bResult);
}
int main()
{
CHANGER_PRODUCT_DATA Data;
if(!GetDiskInfo(&Data)
{
cout<<Coul not rtrieve seial nuimber\n"
exit(0);
}
cout<<Data.SerialNumber<<"\n";
return 1;
}
推荐答案
BOOL GetDiskInfo(CHANGER_PRODUCT_DATA *Data)
{
HANDLE hDevice;
BOOL bResult;
DWORD junk;
hDevice = CreateFile(_T("\\\\.\\C:"),
0,
FILE_SHARE_WRITE,
NULL,
OPEN_EXISTING,
0,
NULL);
if(hDevice == INVALID_HANDLE_VALUE)
{
cout << "could not access disk\n";
return FALSE;
}
bResult = DeviceIoControl(hDevice,
IOCTL_VOLUME_GET_VOLUME_DISK_EXTENTS,
NULL,
0,
Data,
sizeof(*Data),
&junk,
NULL);
CloseHandle(hDevice);
return bResult;
}
这篇关于请谁能告诉我为什么此磁盘序列号检索程序不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!