バッテリーレベルの変化に基づいてTSでタスクを作成する必要があります。バッテリーが67%から66%に低下したとしましょう。このイベントに基づいてタスクを実行するにはどうすればよいですか。Windowsはこれをログに記録しますか?この情報はどこにも見つかりませんでした。
バッテリーレベルの変化に基づいてTSでタスクを作成する必要があります。バッテリーが67%から66%に低下したとしましょう。このイベントに基づいてタスクを実行するにはどうすればよいですか。Windowsはこれをログに記録しますか?この情報はどこにも見つかりませんでした。
回答:
Windowsはこの種の詳細をイベントとして記録しません。ただし、以下のバッチファイルのようなものを使用して、カスタムイベントを作成できます。
このバッチファイルは、現在のバッテリ充電率を監視し、充電量がユーザー定義のしきい値を下回った場合にユーザー定義のイベントを作成します。
@echo off
setlocal EnableDelayedExpansion
rem set threshold value
set _threshold=82
:start
rem get the battery charge
rem use findstr to strip blank lines from wmic output
for /f "usebackq skip=1 tokens=1" %%i in (`wmic Path Win32_Battery Get EstimatedChargeRemaining ^| findstr /r /v "^$"`) do (
  set _charge=%%i
  echo !_charge!
  if !_charge! lss !_threshold! (
    echo threshold reached
    rem create a custom event in the application event log
    rem requires administrator privileges 
    eventcreate /l APPLICATION /t WARNING /ID 999 /D "Battery charge has dropped"
    goto :done
    ) else (
    rem wait for 10 minutes then try again
    timeout /t 600 /nobreak
    goto :start
    )
  )
:done
endlocal
ノート:
EventcreateWindowsの10までを含むのWindows XP上のコマンドの動作は、それが仕事に管理者権限が必要です_threshold必要に応じて設定999APPLICATIONイベントログに説明とともに生成されますBattery charge has droppedeventcreate状況に応じてコマンドを変更します。timeout状況に応じて遅延を変更します。出力例:
現在、バッテリーの充電量は81%です。しきい値をに設定しました82。ここで私が実行するとどうなりますかBattery.cmd:
> battery
81
threshold reached
SUCCESS: An event of type 'WARNING' was created in the 'APPLICATION' log with 'EventCreate' as the source.
そして、これがイベントログの新しいエントリです。
EVENTCREATE [/S system [/U username [/P [password]]]] /ID eventid
            [/L logname] [/SO srcname] /T type /D description
Description:
    This command line tool enables an administrator to create
    a custom event ID and message in a specified event log.
Parameter List:
    /S    system           Specifies the remote system to connect to.
    /U    [domain\]user    Specifies the user context under which
                           the command should execute.
    /P    [password]       Specifies the password for the given
                           user context. Prompts for input if omitted.
    /L    logname          Specifies the event log to create
                           an event in.
    /T    type             Specifies the type of event to create.
                           Valid types: SUCCESS, ERROR, WARNING, INFORMATION.
    /SO   source           Specifies the source to use for the
                           event (if not specified, source will default
                           to 'eventcreate'). A valid source can be any
                           string and should represent the application
                           or component that is generating the event.
    /ID   id               Specifies the event ID for the event. A
                           valid custom message ID is in the range
                           of 1 - 1000.
    /D    description      Specifies the description text for the new event.
    /?                     Displays this help message.
Examples:
    EVENTCREATE /T ERROR /ID 1000
        /L APPLICATION /D "My custom error event for the application log"
    EVENTCREATE /T ERROR /ID 999 /L APPLICATION
        /SO WinWord /D "Winword event 999 happened due to low diskspace"
    EVENTCREATE /S system /T ERROR /ID 100
        /L APPLICATION /D "Custom job failed to install"
    EVENTCREATE /S system /U user /P password /ID 1 /T ERROR
        /L APPLICATION /D "User access failed due to invalid user credentials"
イベントがID 13のMicrosoft-Windows-BatteryETWプロバイダーがありBatteryPercentRemainingます。TraceEventを使用するプロジェクトをコーディングして、このプロバイダーのリアルタイムリスナーを作成できMicrosoft-Windows-Batteryます。イベントには、RemainingPercentageステータスPercentageChangeを表示し、変更を確認するためのエントリがあります。
このイベントが表示され、の-1変更が表示されPercentageChangeたら、必要なプログラムを実行します。
OK、DavidPostillが提供するスクリプトは機能しません。それは素晴らしいスクリプトですが、コードは不規則であるか、古くなっています。
@echo off
setlocal EnableDelayedExpansion
rem set threshold value
set _threshold=30
:start
rem get the battery charge
rem use findstr to strip blank lines from wmic output
for /f "usebackq skip=1 tokens=1" %%i in (`wmic Path Win32_Battery Get EstimatedChargeRemaining ^| findstr /r /v "^$"`) do (
  set _charge=%%i
  echo !_charge!
  if !_charge! lss !_threshold! (
    echo threshold reached
    rem create a custom event in the application event log
    rem requires administrator privileges
    eventcreate /l APPLICATION /t WARNING /ID 999 /D "Battery charge has dropped below the threshold."
    goto :done
  ) else (
    rem wait for 1 minute then try again
    timeout /t 60 /nobreak
    goto :start
  )
)
:done
endlocal
私はこの編集をDavidPostillの回答に提案しましたが、なぜそれが承認されなかったのかわかりません...
findstrが多く誤っていることがわかりました。せっかく、マイクロソフト?私は仕事を成し遂げるためのDavidPostillの汚い小さなハックに感銘を受けました。
                    バッテリー残量を確認する簡単な方法があります。ナビゲーションエリアで、バッテリーアイコンの上にマウスを置くだけで、パーセンテージが表示されます。