2013-06-23 84 views
1

任何人都可以建議如何列出以下內容,最好在.net在C中列出其驅動程序的磁盤驅動器#

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他們的司機,但是我不能那麼這些映射驅動器。

回答

0

我找到了我需要用下面的函數,從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); 
相關問題