private void Form1_Load(object sender, EventArgs e)
{
listBox1.Items.Clear();//清空列表
SelectQuery selectQuery = new SelectQuery("select * from win32_logicaldisk");//从WMI中查询信息
ManagementObjectSearcher searcher = new ManagementObjectSearcher(selectQuery);//创建WMI管理对象
foreach (ManagementObject disk in searcher.Get())//遍历查询到的信息
{
string DriveType;//定义一个变量,用来存储驱动器类型
DriveType = disk["DriveType"].ToString();//获取驱动器类型
if (DriveType == "4")//判断驱动器类型
listBox1.Items.Add(disk["Name"].ToString());//将驱动器添加到列表中
}
}
亲爱的:被墙域名跳转TG:@qianhenetwork QQ:851617266,可否收藏+评论+分享呢?
文章评论 本文章有个评论