我正在尝试使用功能确定驱动器是否是系统保留驱动器(PhysicalDrive0
或C-Drive
)DeviceIoControl
。但是,对于所有驱动器,我的代码始终返回 true。
HANDLE hDevice; // handle to the drive to be examined
BOOL bResult; // results flag
DWORD junk; // discard results
PARTITION_INFORMATION_MBR *pdg
hDevice = CreateFile(TEXT("\\\\.\\C:"), GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ |
FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL);
bResult = DeviceIoControl(
hDevice, // device to be queried
IOCTL_DISK_GET_PARTITION_INFO_EX, // operation to perform
NULL, 0, // no input buffer
pdg, sizeof(*pdg), // output buffer
&junk, // # bytes returned
(LPOVERLAPPED) NULL // synchronous I/O
);
bResult
is始终返回0,表示函数成功。- 甚至
pdg->PartitionType
有垃圾信息也不回true
。