了解电池状态,在C#或.NET

编程入门 行业动态 更新时间:2024-10-23 13:34:26
本文介绍了了解电池状态,在C#或.NET的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个获取详细的系统信息的应用程序,我已经能够得到剩余电量的百分比,但是电池本身不是个百分点。

I have an application that gets detailed system information, and I have been able to get the percent of charge remaining but not the percent of the battery itself.

说明:随着时间的推移,电池慢慢会变得越来越坏,和一些应用程序,像笔记本电脑戴尔支持中心,显示电池状态,不能充电的状态,这曾经是100%,但现在是90%。

Explanation: As time goes on, the battery slowly gets worse and worse, and some applications, like Dell Support Center on Laptops, display the status of the battery, not the status of the charge, which used to be 100% but now is 90%.

我怎样才能在C#中这个值还是.NET?

How can I get this value in C# or .NET?

推荐答案

不要有一台笔记本电脑来测试,但我猜你可以使用WMI类Win32_Battery.

Don't have a laptop to test with, but I'm guessing you could use the WMI class Win32_Battery.

它有两个字段,看起来有趣 - 为DesignCapacity ,它告诉你

It has two fields that look interesting - DesignCapacity, which tells you

设计容量的电池毫瓦-小时。

Design capacity of the battery in milliwatt-hours.

和 Full- ChargeCapacity的,其中有迷人的注意,

and FullChargeCapacity, which has the fascinating note that

在电池毫瓦小时的完全充电容量。将值DesignCapacity的属性的比较确定当电池需要更换。

Full charge capacity of the battery in milliwatt-hours. Comparison of the value to the DesignCapacity property determines when the battery requires replacement.

所以我的猜测是,你可以使用WMI来阅读这两个值,然后计算 Full- ChargeCapacity的/为DesignCapacity 找电池的健康百分比数字。

So my guess is that you can use WMI to read these two values, and then calculate FullChargeCapacity/DesignCapacity to find the battery health percentage number.

修改

下面是访问使用C#WMI信息的一个简单的例子。我第一次添加的引用, System.Management 组装。然后:

Here's a brief example of accessing WMI information using C#. I first added a reference to the System.Management assembly. Then:

using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Management; namespace ConsoleApplication1 { class Program { static void Main(string[] args) { System.Management.ObjectQuery query = new ObjectQuery("Select * FROM Win32_Battery"); ManagementObjectSearcher searcher = new ManagementObjectSearcher(query); ManagementObjectCollection collection = searcher.Get(); foreach (ManagementObject mo in collection) { foreach (PropertyData property in mo.Properties) { Console.WriteLine("Property {0}: Value is {1}", property.Name, property.Value); } } } } }

另外请注意,你基本上运行针对WMI类似SQL的查询,这样你就可以改变,如果你想要的。 Windows管理规范查询语言或 WQL ,是你想要的搜索更多地了解它。

Also, note that you are basically running a SQL-like query against WMI, so you can vary that if you want. Windows Management Instrumentation Query Language, or WQL, is what you want to search for to learn more about it.

另外看看ahawker的回答,它可能最终会被更多的帮助,如果WMI未正确捕获的电池数据,他说。

Also take a look at ahawker's answer, it may end up being more helpful if WMI isn't properly capturing the battery data, as he notes.

更多推荐

了解电池状态,在C#或.NET

本文发布于:2023-11-25 14:07:46,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1630065.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:电池   状态   NET

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!