有人可以建议如何列出以下内容,最好是.net
吗?
Driver Letter, Device Driver
我可以使用以下方式获得有关连接到计算机的驱动器的一些相当基本的信息:
DriveInfo[] drives = DriveInfo.GetDrives();
我可以使用WMI获取更多信息,但我无法获得与每个驱动器关联的设备驱动程序:
SelectQuery query = new SelectQuery("select * from win32_DiskDrive");
ManagementObjectSearcher searcher = new ManagementObjectSearcher(query);
我可以使用Win.OBJECT_DIRECTORY_INFORMATION
列出其驱动程序的设备ID,但是我无法将这些ID映射到驱动器。
答案 0 :(得分:1)
private static string GetRealPath(string path)
{
string realPath = path;
StringBuilder pathInformation = new StringBuilder(250);
string driveLetter = Path.GetPathRoot(realPath).Replace("\\", "");
QueryDosDevice(driveLetter, pathInformation, 250);
// If drive is substed, the result will be in the format of "\??\C:\RealPath\".
// Strip the \??\ prefix.
string realRoot = pathInformation.ToString().Remove(0, 4);
//Combine the paths.
realPath = Path.Combine(realRoot, realPath.Replace(Path.GetPathRoot(realPath), ""));
return realPath;
}
[DllImport("kernel32.dll")]
static extern uint QueryDosDevice(string lpDeviceName, StringBuilder lpTargetPath, int ucchMax);