根据逻辑盘符(如:C:)求该盘符号对应连接的IDE或者SATA设备,要求不用WMI,不读直接读硬盘相关信息。解决办法

根据逻辑盘符(如:C:)求该盘符号对应连接的IDE或者SATA设备,要求不用WMI,不读直接读硬盘相关信息。
如题,先谢谢大家了!

------解决方案--------------------
表达不够清楚,要得到什么?最好举个例子说明一下。
“不读直接读硬盘相关信息”又是什么意思?
------解决方案--------------------
尝试用DeviceIOControl发送存储设备通用的指令
你为什么不用WMI?这是Windows的标准接口,比DeviceIOControl好用的多


------解决方案--------------------
关注..........
------解决方案--------------------
DeviceIoControl似乎没有这种功能。
如果用驱动程序,可以参考一下IoGetDeviceProperty,但不确定是否包含这些信息。
------解决方案--------------------
获取逻辑盘的父设备,遍历获取所有硬盘的父设备,看那块盘的父设备与逻辑盘相同
------解决方案--------------------
#include <windows.h>
#include <winioctl.h>
#include <stdio.h>

BOOL GetDriveGeometry(DISK_GEOMETRY *pdg)
{
HANDLE hDevice; // handle to the drive to be examined 
BOOL bResult; // results flag
DWORD junk; // discard results

hDevice = CreateFile(TEXT("\\\\.\\PhysicalDrive0"), // drive 
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
{
return (FALSE);
}

bResult = DeviceIoControl(hDevice, // device to be queried
IOCTL_DISK_GET_DRIVE_GEOMETRY, // operation to perform
NULL, 0, // no input buffer
pdg, sizeof(*pdg), // output buffer
&junk, // # bytes returned
(LPOVERLAPPED) NULL); // synchronous I/O

CloseHandle(hDevice);

return (bResult);
}

int main(int argc, char *argv[])
{
DISK_GEOMETRY pdg; // disk drive geometry structure
BOOL bResult; // generic results flag
ULONGLONG DiskSize; // size of the drive, in bytes

bResult = GetDriveGeometry (&pdg);

if (bResult) 
{
printf("Cylinders = %I64d\n", pdg.Cylinders);
printf("Tracks/cylinder = %ld\n", (ULONG) pdg.TracksPerCylinder);
printf("Sectors/track = %ld\n", (ULONG) pdg.SectorsPerTrack);
printf("Bytes/sector = %ld\n", (ULONG) pdg.BytesPerSector);

DiskSize = pdg.Cylinders.QuadPart * (ULONG)pdg.TracksPerCylinder *
(ULONG)pdg.SectorsPerTrack * (ULONG)pdg.BytesPerSector;
printf("Disk size = %I64d (Bytes) = %I64d (Gb)\n", DiskSize,
DiskSize / (1024 * 1024 * 1024));

else 
{
printf ("GetDriveGeometry failed. Error %ld.\n", GetLastError ());
}

return ((int)bResult);
}
------解决方案--------------------
DISK_GEOMETRY_EX is used in conjunction with the IOCTL_DISK_GET_DRIVE_GEOMETRY_EX and the IOCTL_DISK_GET_MEDIA_TYPES IOCTLs, in order to retrieve information about the geometry of a physical disk (media type, number of cylinders, tracks per cylinder, sectors per track, and bytes per sector).

Since the partition and detect information are not at fixed locations within the DISK_GEOMETRY_EX structure, htdddisk.h provides two macros for accessing this information. Both macros take a pointer to a structure of type DISK_GEOMETRY_EX as an argument: