首页 > 代码库 > WPF WMI

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