Ở đây bạn có thể nhận được danh sách các ổ cứng 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
}
}
}
Ở đây bạn có thể nhận được danh sách tất cả các ổ đĩa cố định (hệ thống và USB ổ đĩa cứng):
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);
}
}
Nếu bạn so sánh chúng, sau đó bạn có thể lấy danh sách các ổ đĩa cố định trong một hệ thống nhưng không có Ổ cứng USB.
xin lỗi nhưng internet đã ngừng hoạt động, hãy kiểm tra liên kết bên dưới ... –