2012-08-09 105 views
-1

請幫助我獲取筆記本電腦/平板電腦「BatteryCycleCount」的值。基於這個屬性,我們將決定更換電池。 下面是一些API,這我在谷歌上搜索發現:筆記本電腦/平板電腦BatteryCycleCount用於確定其健康狀況

[DllImport("setupapi.dll", SetLastError = true)] 
protected static extern IntPtr SetupDiGetClassDevs(ref Guid gClass, [MarshalAs(UnmanagedType.LPStr)] string strEnumerator, IntPtr hParent, uint nFlags); 

[DllImport("setupapi.dll", SetLastError = true)] 
protected static extern bool SetupDiEnumDeviceInterfaces(IntPtr lpDeviceInfoSet, uint nDeviceInfoData, ref Guid gClass, uint nIndex, ref SP_DEVICE_INTERFACE_DATA oInterfaceData); 

[DllImport("setupapi.dll", SetLastError = true)] 
protected static extern bool SetupDiGetDeviceInterfaceDetail(IntPtr lpDeviceInfoSet, ref SP_DEVICE_INTERFACE_DATA oInterfaceData, ref SP_DEVICE_INTERFACE_DETAIL_DATA oDetailData, uint nDeviceInterfaceDetailDataSize, ref uint nRequiredSize, IntPtr lpDeviceInfoData); 

[DllImport("kernel32.dll", SetLastError = true)] 
protected static extern IntPtr CreateFile([MarshalAs(UnmanagedType.LPStr)] string strName, uint nAccess, uint nShareMode, IntPtr lpSecurity, uint nCreationFlags, uint nAttributes, IntPtr lpTemplate); 

[DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)] 
public static extern bool DeviceIoControl([In] SafeHandle hDevice, [In] int dwIoControlCode, [In] IntPtr lpInBuffer, [In] int nInBufferSize, [Out] IntPtr lpOutBuffer, [In] int nOutBufferSize, out int lpBytesReturned, [In] IntPtr lpOverlapped); 
+0

...你的問題是? – 2012-08-09 07:23:36

回答

0

而不是直接使用Windows API,你可以請求的性能計數器類別中的「電池狀態」。

編輯:

在類別「電池狀態」中的計數器是多實例:每個電池之一。在我的筆記本電腦,我可以這樣寫C#代碼:

var counter = new PerformanceCounter("BatteryStatus", "RemainingCapacity", "ACPI\PNP0C0A\0_0", true); 
var remainingCapacity = counter.NextValue(); 

您可以查看類別中的「電池狀態」性能監視器(「性能監視器」命令)中的所有可用的計數器。

+0

什麼「範疇」?你將如何在不調用API函數的情況下創建這個「請求」? – 2012-08-09 07:43:02

+0

我編輯了我的答案。 – schglurps 2012-08-09 08:49:31