【问题标题】:How to programmatically emulate battery in Windows workstation without battery device?如何在没有电池设备的情况下以编程方式模拟 Windows 工作站中的电池?
【发布时间】:2018-06-02 16:14:43
【问题描述】:

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

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

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

【问题讨论】:

    标签: windows battery


    【解决方案1】:

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

    长指令:

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

    2. 创建虚拟机

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

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

    5. 在 Visual Studio 中,在主菜单 Driver > Test > Configure Devices 添加要安装的虚拟机 (WDTF) Runtime Libraries。

    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://docs.microsoft.com/en-us/windows-hardware/drivers/ddi/content/_dtf/

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

    【讨论】:

      【解决方案2】:

      Oleg 的回答很简单,但我无法让它模拟电池 - 禁用和启用真实电池的操作确实成功了。

      PS C:\RunTime> .\RegisterWDTF.exe
      This version of WDTF is compatible with Windows Build 17763.
      -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\wdtfsensorsiosimpleioaction.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:\RunTime\WDTF.DLL".
      -Update registry state.
      -Install Drivers.
      -Done
      
       WDTF Registration Successful
      PS C:\RunTime> cscript.exe .\fake-battery.vbs
      Microsoft (R) Windows Script Host Version 5.812
      Copyright (C) Microsoft Corporation. All rights reserved.
      
      Loading Wex.Logger.dll from systemdata.cpp linep 922 failed.
      WDTF_TARGET               : INFO  :  - GetInterface("SimulatedBatterySystem")
      WDTF_TARGET               : INFO  :          Target: ORANGE
      WDTF_SIMBATT              : INFO  : DisableRealBatteries()
      WDTF_SIMBATT              : INFO  : EnableSimulatedBattery()
      WDTF_SIMBATT              : ERROR : SimulatedBatterySystem critical error installing battbus device. HRESULT=0xE0000203
      C:\RunTime\fake-battery.vbs(22, 1) WDTF.SimulatedBatterySystem.1: SimulatedBatterySystem critical error installing battbus device. HRESULT=0xE0000203
      

      很遗憾,我在公共 Internet 上找不到有关这些错误的信息。希望有人遇到这种情况并知道下一步该做什么!

      --

      编辑:似乎 Visual Studio 除了安装测试框架外还安装了各种驱动程序,因此仅复制 RunTime 文件夹是不够的。我最终使用来自另一个工作站的 VS 将我的工作站添加为完整目标。然后让我模拟电池。

      【讨论】:

      • 0xe0000203 - ERROR_NO_DRIVER_SELECTED - 没有看到这个错误。您是否有可能在 VM 和 Workstation 上使用了不同的操作系统/操作系统版本?
      • 我都使用了 Win10 1809 Enterprise 64 位,但我确实考虑过这种可能性,尽管远程的一个考虑到禁用/启用真正的电池成功 - 我也可以尝试使用工作站作为Visual Studio 中的测试目标(如果允许)。
      • 查看我上面的编辑 - VS 安装了一些驱动程序来补充测试框架。一旦我在我的工作站上安装了这些驱动程序,我就能够正确地模拟电池。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-03-15
      相关资源
      最近更新 更多