Can I construct the device names manually instead of using some API? For example, I want to use the Physical Drive 2, but the following code fails(hDrive == INVALID_HANDLE_VALUE
):
QString drivePath = QString("\\.\PhysicalDrive2");
HANDLE hDrive = CreateFileW((LPCWSTR)drivePath.utf16(), GENERIC_READ,
FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING,
0, NULL);
if (hDrive == INVALID_HANDLE_VALUE) {
qDebug() << "Failed to open drive 2";
}
Is there any simple pattern for disk device names like \\.\PhysicalDrive*
, so I can replace * with a number and try until the CreateFileW
function succeeds? In Linux, the disk device name is like /dev/sda, /dev/sdb,…, so I can always try till succeed.
In Qt, I can list device names using QStorageInfo but only limited to mounted devices. For unmounted devices, how can I get their device names?