我将 Win32_Battery class与C#一起使用,以便在几分钟内获得剩余时间为电池充电。但它对我不起作用。
我的代码:
using System;
using System.Management;
using System.Windows.Forms;
namespace WMISample
{
public class MyWMIQuery
{
public static void Main()
{
try
{
ManagementObjectSearcher searcher =
new ManagementObjectSearcher("root\\CIMV2",
"SELECT * FROM Win32_Battery");
foreach (ManagementObject queryObj in searcher.Get())
{
Console.WriteLine("-----------------------------------");
Console.WriteLine("Win32_Battery instance");
Console.WriteLine("-----------------------------------");
Console.WriteLine("TimeToFullCharge: {0}", queryObj["TimeToFullCharge"]);
}
}
catch (ManagementException e)
{
MessageBox.Show("An error occurred while querying for WMI data: " + e.Message);
}
}
}
}