WPF WMI

Posted on 2017-05-26 15:14  KA卡尔特人头狼  阅读(173)  评论(0编辑  收藏  举报

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 "";
}
}