Determine whether the U disk can be written

#include <stdio.h>
#include <windows.h>
#include <winioctl.h>

int main(void)
{
HANDLE hFile = CreateFile("\\\\.\\G:",GENERIC_READ,FILE_SHARE_READ,NULL,OPEN_EXISTING,0,NULL);

DWORD temp;
BOOL bRet = DeviceIoControl(hFile,IOCTL_DISK_IS_WRITABLE,NULL,0,NULL,0,&temp,NULL);

if (!bRet)
{
printf("Error code:%x\n",GetLastError());
}

return 0;
}

Reproduced in: https: //www.cnblogs.com/fanzi2009/archive/2009/05/05/1449899.html

Guess you like

Origin blog.csdn.net/weixin_34343308/article/details/94192499