2013-06-23 3 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); 

Я могу перечислить идентификатор устройства с их использованием драйверов 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);