#include <stdio.h>
#include <windows.h>
#include <winioctl.h>
int main(void)
{
//LPCTSTR lpszDevice = "\\\\.\\PhysicalDrive0";
LPCTSTR lpszDevice = "\\\\.\\C:";
HANDLE hDevice = CreateFile(lpszDevice,GENERIC_READ,FILE_SHARE_READ|FILE_SHARE_WRITE,NULL,OPEN_EXISTING,0,NULL);
if (!hDevice || (hDevice==(HANDLE)-1))
{
printf("Open Device error:%x\n",GetLastError());
return -1;
}
DWORD temp;
DISK_GEOMETRY DiskGeometry;
BOOL bRet = DeviceIoControl(hDevice,IOCTL_DISK_GET_DRIVE_GEOMETRY,NULL,0,&DiskGeometry,sizeof(DISK_GEOMETRY),&temp,NULL);
if (!bRet)
{
printf("IOCTL_DISK_GET_DRIVE_GEOMETRY Error code:%x\n",GetLastError());
}
PARTITION_INFORMATION parti_info;
bRet = DeviceIoControl(hDevice,IOCTL_DISK_GET_PARTITION_INFO,NULL,0,&parti_info,sizeof(PARTITION_INFORMATION),&temp,NULL);
if (!bRet)
{
printf("IOCTL_DISK_GET_PARTITION_INFOIOCTL_DISK_GET_PARTITION_INFO Error code:%x\n",GetLastError());
}
CloseHandle(hDevice);
return 0;
}
转载于:https://www.cnblogs.com/fanzi2009/archive/2010/06/04/1751712.html