WPF WMI
Posted 卡尔特人头狼
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了WPF WMI相关的知识,希望对你有一定的参考价值。
Add Reference:System.Management;
using System.Management;
private string CheckDisk()
{
try
{
ManagementObjectSearcher searcher = new ManagementObjectSearcher("Select * From Win32_LogicalDisk");
string sDisc = ""; //盘符
double dCurSize = 0.0;
//test
// string sCurPath = "";
// sCurPath = System.Environment.CurrentDirectory;
// var ini = new IniFile(sCurPath + "\\debug.ini");
// int i = 0;
foreach (ManagementObject mo in searcher.Get())
{
string disc = mo["Name"].ToString().Trim();
string size = mo["Size"].ToString().Trim();
string DriveType = mo["DriveType"].ToString().Trim();
if(string.Compare(DriveType,"3") == 0)
{
double dSize = Convert.ToDouble(size);
if (dSize > dCurSize) //string.Compare(size, sSize) > 0
{
sDisc = disc;
dCurSize = dSize;
// string sCurDisc = String.Format("CurDisc{0}", i);
// ini.IniWritevalue("SYSTEM", sCurDisc, sDisc);
}
}
// i++;
}
return sDisc;
}
catch
{
return "";
}
}
以上是关于WPF WMI的主要内容,如果未能解决你的问题,请参考以下文章
C#下通过wbemtest和WMI Code Cretor更加高效的访问WMI