windows - 如何在没有电池设备的情况下以编程方式模拟 Windows 工作站中的电池?

标签 windows battery

出于测试目的,我需要强制 Windows 认为它​​在工作站 PC 上有电池。

有没有办法在没有电池设备的Windows工作站中伪造/模拟/模拟/模拟电池状态/低电量/充电/放电?

我可以在 Windows 上以编程方式设置电池电量吗?

最佳答案

tl;dr:使用Windows Driver Testing Framework (WDTF) Runtime Libraries来自 Windows 驱动程序工具包 (WDK)

长指令:

  1. 使用 Windows 驱动程序工具包 (WDK) 安装 Visual Studio

  2. 创建虚拟机

  3. 搜索 WDK Test Target Setup x64-x64_en-us.msiC:\Program Files (x86)\Windows Kits

  4. 安装 WDK Test Target Setup x64-x64_en-us.msi在虚拟机上。

  5. 在 Visual Studio 中,在主菜单“驱动程序”>“测试”>“配置设备”中添加要安装 (WDTF) 运行时库的虚拟机。 simulate windows battery device

  6. 来自虚拟机复制文件夹 C:\Program Files (x86)\Windows Kits\10\Testing\Runtimes\WDTF\RunTime在您的工作站上

  7. 来自 RunTime以管理员身份运行文件夹 RegisterWDTF.exe

输出:

C:\RunTime>RegisterWDTF.exe
-Delete registry state.
-Get registry path.
-Register COM DLLs.
   Process "C:\RunTime\Actions\Deprecated\DeviceManagement.dll".
   Process "C:\RunTime\Actions\DeviceSupport\WDTFDeviceSupportAction.dll".
   Process "C:\RunTime\Actions\DrvPkgLibExt.dll".
      Not a COM DLL

   Process "C:\RunTime\Actions\EDT\WDTFEDTAction.dll".
   Process "C:\RunTime\Actions\IoSpy\WDTFIoAttackAction.dll".
   Process "C:\RunTime\Actions\IoSpy\WDTFIoSpyAction.dll".
   Process "C:\RunTime\Actions\SimpleIO\SimpleIO_D3DTest.dll".
   Process "C:\RunTime\Actions\SimpleIO\WDTFAnySimpleIoAction.dll".
   Process "C:\RunTime\Actions\SimpleIO\WDTFAudioSimpleIoAction.dll".
   Process "C:\RunTime\Actions\SimpleIO\WDTFBluetoothSimpleIoAction.dll".
   Process "C:\RunTime\Actions\SimpleIO\WDTFCDROMSimpleIoAction.dll".
   Process "C:\RunTime\Actions\SimpleIO\WDTFMobileBroadbandSimpleIoAction.dll".
   Process "C:\RunTime\Actions\SimpleIO\WDTFMUTT2STRESSSimpleIoAction.dll".
   Process "C:\RunTime\Actions\SimpleIO\WDTFMUTT2TCDSimpleIoAction.dll".
   Process "C:\RunTime\Actions\SimpleIO\WDTFNetworkSimpleIoAction.dll".
   Process "C:\RunTime\Actions\SimpleIO\WDTFVolumeSimpleIoAction.dll".
   Process "C:\RunTime\Actions\SimpleIO\WDTFWebcamSimpleIoAction.dll".
   Process "C:\RunTime\Actions\SimpleIO\WDTFWirelessSimpleIoAction.dll".
   Process "C:\RunTime\Actions\SimpleIO\WDTFWPDSimpleIoAction.dll".
   Process "C:\RunTime\Actions\SimulatedBattery\WDTFSimulatedBatterySystemAction.dll".
   Process "C:\RunTime\Actions\System\WDTFSystemAction.dll".
   Process "C:\RunTime\Actions\WDTFConcurrentIOAction.dll".
   Process "C:\RunTime\Actions\WDTFCpuUtilizationSystemAction.dll".
   Process "C:\RunTime\Actions\WDTFDriverPackageAction.dll".
   Process "C:\RunTime\Actions\WDTFDriverSetupDeviceAction.dll".
   Process "C:\RunTime\Actions\WDTFDriverSetupSystemAction.dll".
   Process "C:\RunTime\Actions\WDTFDriverVerifierSystemAction.dll".
   Process "C:\RunTime\Actions\WDTFFuzzTestAction.dll".
   Process "C:\RunTime\Actions\WDTFInterfaces\WDTFInterfaces.dll".
   Process "C:\RunTime\Actions\WDTFPNPAction.dll".
   Process "C:\RunTime\Actions\WDTFSUPAction.dll".
   Process "C:\WDTF.DLL".
-Update registry state.
-Install Drivers.
-Done

 WDTF Registration Successful

现在您可以在程序语言中使用 COM 对象“WDTF2.WDTF”,如以下 VBScript 示例所示:

'
' Variable defenition 
'
Dim WDTF
Dim SimulatedBatterySystemSystemAction


'
' Create WDTF object
'
Set WDTF = CreateObject("WDTF2.WDTF")

'
'  Get your newly created SimulatedBatterySystem action interface
'
Set SimulatedBatterySystemSystemAction = WDTF.SystemDepot.ThisSystem.GetInterface("SimulatedBatterySystem")


'  enable the simulated battery
SimulatedBatterySystemSystemAction.EnableSimulatedBattery()

'  disable real batteries
SimulatedBatterySystemSystemAction.DisableRealBatteries()

'  set to DC power status
SimulatedBatterySystemSystemAction.SetSimulatedBatteryToDC()

'  set to 50% charge level
SimulatedBatterySystemSystemAction.SetSimulatedBatteryChargePercentage(50)

WScript.Sleep 10000 

'  set to AC power status
SimulatedBatterySystemSystemAction.SetSimulatedBatteryToAC()

'  enable real batteries
SimulatedBatterySystemSystemAction.EnableRealBatteries()

'  disable the simulated battery
SimulatedBatterySystemSystemAction.DisableSimulatedBattery()

这里所有WDTF引用:https://learn.microsoft.com/en-us/windows-hardware/drivers/ddi/content/_dtf/

以防万一,Linux假电池模块:https://github.com/hoelzro/linux-fake-battery-module

关于windows - 如何在没有电池设备的情况下以编程方式模拟 Windows 工作站中的电池?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50658822/

相关文章:

c++ - 反向动态链接函数调用

给笔记本电池充放电的Python脚本

ios - uidevicebatterystatedidchangenotification 有时不工作

windows - 滥用 RegisterWindowMessage 会导致资源耗尽吗?

windows - Windows 上的 Git 和文件属性

iPhone 显着位置变化会导调用池耗尽吗?

android - 在Android编程中,我可以为一个Activity注册多个BroadcastReceiver吗?

Javascript Battery API 返回无限放电时间

windows - 64 位 Windows 中的程序集系统调用

node.js - 将 HTTPS 分配给 node.js socket.io