سرخط خبرها
خانه » C# » بدست آوردن مشخصات فلش مموری در C# Finding a USB mass storage devices “disk letter” by its PID and VID number or name

بدست آوردن مشخصات فلش مموری در C# Finding a USB mass storage devices “disk letter” by its PID and VID number or name

void P_Add(string str_Input)
{
txt_new_Temp.Text += Environment.NewLine + str_Input;
}

private void button2_Click(object sender, EventArgs e)
{
ManagementObjectSearcher diskDrives = new ManagementObjectSearcher(“SELECT * FROM Win32_DiskDrive WHERE InterfaceType=’USB'”);
foreach (ManagementObject diskDrive in diskDrives.Get())
{
string DeviceID = diskDrive[“DeviceID”].ToString();
string DriveLetter = “”;
string DriveDescription = “”;

// associate physical disks with partitions
ManagementObjectSearcher partitionSearcher = new ManagementObjectSearcher(String.Format(
“associators of {{Win32_DiskDrive.DeviceID='{0}’}} where AssocClass = Win32_DiskDriveToDiskPartition”,
diskDrive[“DeviceID”]));

foreach (ManagementObject partition in partitionSearcher.Get())
{
// associate partitions with logical disks (drive letter volumes)
ManagementObjectSearcher logicalSearcher = new ManagementObjectSearcher(String.Format(
“associators of {{Win32_DiskPartition.DeviceID='{0}’}} where AssocClass = Win32_LogicalDiskToPartition”,
partition[“DeviceID”]));

foreach (ManagementObject logical in logicalSearcher.Get())
{
// finally find the logical disk entry to determine the volume name
ManagementObjectSearcher volumeSearcher = new ManagementObjectSearcher(String.Format(
“select * from Win32_LogicalDisk where Name='{0}'”,
logical[“Name”]));

foreach (ManagementObject volume in volumeSearcher.Get())
{
DriveLetter = volume[“Name”].ToString();
if (volume[“VolumeName”] != null)
DriveDescription = volume[“VolumeName”].ToString();

char VolumeLetter = DriveLetter[0];
string VolumeName = DriveDescription;
string Manufacturer = (string)diskDrive[“Manufacturer”];
string MediaType = (string)diskDrive[“MediaType”];
string Model = (string)diskDrive[“Model”];
string SerialNumber = (string)diskDrive[“SerialNumber”];
long Size = Convert.ToInt64(volume[“Size”]);
long FreeSpace = Convert.ToInt64(volume[“FreeSpace”]);

P_Add(“—————–“);
P_Add(“VolumeLetter= ” + VolumeLetter.ToString());
P_Add(“VolumeName= ” + VolumeName);
P_Add(“Manufacturer= ” + Manufacturer);
P_Add(“MediaType= ” + MediaType);
P_Add(“Model= ” + Model);
P_Add(“SerialNumber= ” + SerialNumber);
P_Add(“Size= ” + Size.ToString());
P_Add(“FreeSpace= ” + FreeSpace.ToString());
P_Add(” “);
}
}
}
}
}

https://social.msdn.microsoft.com/Forums/vstudio/en-US/81ff1ede-899b-476a-a313-a61fd32a8618/finding-a-usb-mass-storage-devices-disk-letter-by-its-pid-and-vid-number-or-name?forum=csharpgeneral

همچنین ببینید

Custom Message Box DLL

Download source – 613 KB Introduction I have tried to create a DLL that generates …

پاسخ دهید

نشانی ایمیل شما منتشر نخواهد شد. بخش‌های موردنیاز علامت‌گذاری شده‌اند *