1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
|
#include <windows.h>
#include <winioctl.h>
//--------------------------------------
BOOL isDriveReadOnly(const char *lpDrive)
{
DWORD dwOutBytes;
HANDLE hDevice = CreateFile(lpDrive, 0, 0, 0, OPEN_EXISTING, 0, 0);
if(hDevice != INVALID_HANDLE_VALUE) {
DeviceIoControl(hDevice, IOCTL_DISK_IS_WRITABLE, 0, 0, 0, 0, &dwOutBytes, 0);
CloseHandle(hDevice);
}
return (GetLastError() == ERROR_WRITE_PROTECT);
}
//--------------------------------------
int main(void)
{
const char szDrive[] = "\\\\.\\F:";
printf("Le lecteur %c: est-il 'Read-Only' ? %s\n", szDrive[4], isDriveReadOnly(szDrive) ? "Oui" : "Non");
return 0;
} |
Partager