簡體   English   中英

在C#中列出磁盤驅動器及其驅動程序

[英]List Disk Drives with their Driver in C#

誰能建議如何列出以下內容,最好在.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及其驅動程序,但是我無法將它們映射到驅動器。

通過以下功能,我從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);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM