本文介绍了使用System.Managment的驱动器号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好.我使用下面列出的代码来确定驱动器签名,但我不知道如何获取DriveLetter.

使用System.Management;

字符串签名;
ManagementObjectSearcher搜索程序=新
ManagementObjectSearcher("SELECT * FROM Win32_DiskDrive");
foreach(searcher.Get()中的Managementment wmi_HD)
{

试试
{
签名= wmi_HD ["Signature"].ToString();
}
catch(Exception)
{
签名=未知";
}

MessageBox.Show(Signature);//也需要知道当前的DriveLetter
}

最终目标是获取所需驱动器的签名.

Hi all. I use code listed below to determine Drive Signature, but I don''t know how to get DriveLetter.

using System.Management;

string Signature;
ManagementObjectSearcher searcher = new
ManagementObjectSearcher("SELECT * FROM Win32_DiskDrive");
foreach (ManagementObject wmi_HD in searcher.Get())
{

try
{
Signature = wmi_HD["Signature"].ToString();
}
catch (Exception)
{
Signature = "Unknown";
}

MessageBox.Show(Signature);//need to know current DriveLetter too
}

The final goal is to get a Signature of needed Drive.

推荐答案

private void btnGetDrive_Click(object sender, System.EventArgs e)
{
   // Store this in string array
   string[] drives = Environment.GetLogicalDrives();
   // Loop string 
   foreach(string strDrive in drives)
   {
      // Add items (drives) to the list
      listBox1.Items.Add(strDrive.ToString());
   }
}




这应该为您提供系统上所有驱动器的列表

希望对您有帮助




This should give you the list of all drives on a system

Hope this helps


这篇关于使用System.Managment的驱动器号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 16:06