1

我正在以管理员权限运行以下代码:

HANDLE hDevice = INVALID_HANDLE_VALUE;  // handle to the drive to be examined 
BOOL bResult = FALSE;                 // results flag
DWORD junk = 0;                     // discard results

hDevice = CreateFileW(L"\\\\.\\PhysicalDrive0",          // drive to open
    0,                // no access to the drive
    FILE_SHARE_READ | // share mode
    FILE_SHARE_WRITE,
    NULL,             // default security attributes
    OPEN_EXISTING,    // disposition
    0,                // file attributes
    NULL);            // do not copy file attributes

if (hDevice == INVALID_HANDLE_VALUE)    // cannot open the drive
{
    std::cout << "invalid handle" << std::endl;
    return -1;
}
std::cout << "handle " << hDevice << std::endl;

DRIVE_LAYOUT_INFORMATION_EX        drv_layout_info_ex;
CREATE_DISK        disk;
INT                n;

ZeroMemory(&disk, sizeof(CREATE_DISK));
disk.PartitionStyle = PARTITION_STYLE_MBR;
disk.Mbr.Signature = 0x7B060725;
bResult = ::DeviceIoControl(hDevice, IOCTL_DISK_CREATE_DISK, &disk,
    sizeof(CREATE_DISK), NULL,
    0, &junk, NULL);
if (!bResult)
{
    std::cout << "IOCTL_DISK_CREATE_DISK failed due to " << GetLastError() << std::endl;
    return FALSE;
}

我得到输出:

handle 00000048
IOCTL_DISK_CREATE_DISK failed due to 5

这是拒绝访问。问题是什么?

4

0 回答 0