C #, use the WMI Object to get the percentage of remaining power of the notebook battery

Source: Internet
Author: User

Sometimes you need to monitor the remaining power of the notebook battery. After investigation, you can find that the WMI object can be done.
Before using the WMI object, you must add a reference to System. Management, and then you can call the WMI Object.
The WMI object we use is: Win32_Battery
Object Reference: http://msdn.microsoft.com/zh-cn/library/aa394074 (v = VS.85). aspx
Code:
ManagementClass mc = new ManagementClass ("Win32_Battery ");
ManagementObjectCollection moc = mc. GetInstances ();

ManagementObjectCollection. ManagementObjectEnumerator mom = moc. GetEnumerator ();
If (mom. MoveNext ()){
Console. WriteLine ("EstimatedChargeRemaining: \ t {0 }%", mom. Current. Properties [" EstimatedChargeRemaining "]. Value );
}

Development Environment: VS2010,. Net FrameWork4.0
The Code passes the test in Win7.

 

From the white ocean

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.