1

谁能建议如何列出以下内容,最好是在.net

 Driver Letter, Device Driver

我可以使用以下方法获得有关连接到我的计算机的驱动器的一些相当基本的信息:

DriveInfo[] drives = DriveInfo.GetDrives();

我可以使用 WMI 获取更多信息,但无法获取与每个驱动器关联的设备驱动程序:

 SelectQuery query = new SelectQuery("select * from win32_DiskDrive");
    ManagementObjectSearcher searcher = new ManagementObjectSearcher(query);

我可以使用 列出设备 ID 及其驱动程序Win.OBJECT_DIRECTORY_INFORMATION,但是我不能将它们映射到驱动器。

4

1 回答 1

1

我从http://bloggingabout.net/blogs/ramon/archive/2007/04/05/get-the-physical-path-of-a-path-that-uses-a找到了我需要的以下功能-subst-drive.aspx

    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);
于 2013-06-23T17:53:34.003 回答