无需 WMI 即可获取电池信息

发布于 2024-11-02 09:47:20 字数 491 浏览 0 评论 0原文

有没有办法在没有 WMI 的情况下获取电池 DesignCapacity 和 FullChargeCpacity ? WMI 不支持此值,因此我需要找到其他方法来获取它们。

或者也许有人有更好(更简单)的想法来获取 C# 中电池的磨损程度?

顺便提一句 我尝试以这种方式使用它,但只是返回 null

ManagementObjectSearcher query = 
        new ManagementObjectSearcher("SELECT DesignCapacity FROM Win32_Battery");

foreach (ManagementObject queryObj in query.Get())
{
    string dc = Convert.ToString(queryObj.GetPropertyValue("DesignCapacity"));
    label1.Text = dc + " mAh";
}

谢谢

Is there some way to obtain the battery DesignCapacity and FullChargeCpacity without WMI ?
This values are not supported in WMI so I need to find other way to get them.

Or maybe somebody have better (easier) idea to get the wear level of battery in C#?

BTW
I try to use it this way but just returned null

ManagementObjectSearcher query = 
        new ManagementObjectSearcher("SELECT DesignCapacity FROM Win32_Battery");

foreach (ManagementObject queryObj in query.Get())
{
    string dc = Convert.ToString(queryObj.GetPropertyValue("DesignCapacity"));
    label1.Text = dc + " mAh";
}

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

清风疏影 2024-11-09 09:47:20

要获取这些特定值,您需要针对不同的类而不是 win32_battery 进行单独的查询。

DesignCapacity 可以从 BatteryStaticData 查询

FullChargeCacity 可以从 BatteryFullChargedCapacity 查询

您还需要在代码中使用不同的范围来进行查询。这些类位于 root/WMI 中,而不是 root/cimv2

string scope = "root/WMI";
string query = "SELECT DesignedCapacity FROM BatteryStaticData";

ManagementObjectSearcher batteriesQuery = new ManagementObjectSearcher(scope, query);

ManagementObjectCollection batteries = batteriesQuery.Get();

foreach (ManagementObject battery in batteries)
{
    if (battery != null)
    {
        foreach (var property in battery.Properties)
        {
            Console.Log("Property name: " + property.Name + " Property value: " + property.Value);
        }
    }
}

To get those particular values you need to do separate queries against different classes instead of win32_battery.

DesignCapacity can be queried from BatteryStaticData

FullChargeCacity can be queried from BatteryFullChargedCapacity

You'll need to use a different scope in the code also for the query. These classes are found in root/WMI instead of root/cimv2

string scope = "root/WMI";
string query = "SELECT DesignedCapacity FROM BatteryStaticData";

ManagementObjectSearcher batteriesQuery = new ManagementObjectSearcher(scope, query);

ManagementObjectCollection batteries = batteriesQuery.Get();

foreach (ManagementObject battery in batteries)
{
    if (battery != null)
    {
        foreach (var property in battery.Properties)
        {
            Console.Log("Property name: " + property.Name + " Property value: " + property.Value);
        }
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文