Qui è possibile ottenere l'elenco degli hard disk USB.
//Add Reference System.Management and use namespace at the top of the code.
ManagementObjectSearcher searcher = new ManagementObjectSearcher("SELECT * FROM Win32_DiskDrive WHERE InterfaceType='USB'");
foreach (ManagementObject queryObj in searcher.Get())
{
foreach (ManagementObject b in queryObj.GetRelated("Win32_DiskPartition"))
{
foreach (ManagementBaseObject c in b.GetRelated("Win32_LogicalDisk"))
{
Console.WriteLine(String.Format("{0}" + "\\", c["Name"].ToString())); // here it will print USB drive letter
}
}
}
Qui è possibile ottenere l'elenco di tutte le unità fisse (Sistema e USB dischi rigidi):
DriveInfo[] allDrives = DriveInfo.GetDrives();
foreach (DriveInfo d in allDrives)
{
if (d.IsReady == true && d.DriveType == DriveType.Fixed)
{
Console.WriteLine("Drive {0}", d.Name);
Console.WriteLine(" Drive type: {0}", d.DriveType);
}
}
Se li si confronta, quindi è possibile recuperare l'elenco dei dischi fissi in un sistema, ma senza Hard disk USB.
scusate ma internet non funzionava, controllare il link sottostante ... –