#include <stdio.h>
#include <windows.h>
#include <winioctl.h>
int main(void)
{
// LPCTSTR lpszDevice = "\\\\.\\PhysicalDrive1";
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;
BOOL bRet = DeviceIoControl(hDevice,IOCTL_DISK_IS_WRITABLE,NULL,0,NULL,0,&temp,NULL);
if (!bRet)
{
printf("IOCTL_DISK_IS_WRITABLE Error code:%x\n",GetLastError());
}
const int SECTOR_SIZE = 512;
UCHAR buffer[SECTOR_SIZE];
ReadFile(hDevice,buffer,SECTOR_SIZE,&temp,NULL);
CloseHandle(hDevice);
return 0;
}
转载于:https://www.cnblogs.com/fanzi2009/archive/2010/06/03/1750664.html