배터리 잔량 변경을 위한 Windows 이벤트 ID

배터리 잔량 변경을 위한 Windows 이벤트 ID

배터리 잔량 변경에 따라 TS에서 작업을 생성해야 합니다. 내 배터리가 다음에서 떨어졌다고 가정해 보겠습니다.67%에게66%. 이 이벤트를 기반으로 작업을 어떻게 실행할 수 있습니까? Windows는 이것을 전혀 기록합니까? 이 정보는 어디서도 찾을 수 없었습니다.

답변1

배터리 잔량 변경에 따라 작업 스케줄러에서 작업을 생성해야 합니다.

Windows는 이러한 종류의 세부 정보를 이벤트로 기록하지 않습니다. 그러나 아래 배치 파일과 같은 것을 사용하여 사용자 정의 이벤트를 만들 수 있습니다.


배터리.cmd

이 배치 파일은 현재 배터리 충전율을 모니터링하고 충전량이 사용자 정의 임계값 아래로 떨어지면 사용자 정의 이벤트를 생성합니다.

@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

노트:

  • Eventcreate명령은 Windows XP에서 Windows 10까지 작동하며 작동하려면 관리자 권한이 필요합니다.
  • _threshold필요에 따라 설정
  • 배터리가 이 값 아래로 떨어지면 ID가 포함된 이벤트가 999설명과 함께 APPLICATION 이벤트 로그에 생성됩니다.Battery charge has dropped
  • eventcreate상황에 맞게 명령 을 수정하십시오 .
  • 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 구문

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"

추가 자료

  • Windows CMD 명령줄의 AZ 인덱스- Windows cmd 라인과 관련된 모든 것에 대한 훌륭한 참고 자료입니다.
  • 이벤트 생성- Windows 이벤트 뷰어에서 사용자 정의 이벤트를 생성합니다.
  • Schtasks- 예약된 작업/작업을 생성/편집합니다. 작업은 로컬 또는 원격 컴퓨터에서 생성될 수 있습니다.
  • wmic- Windows 관리 계측 명령.

답변2

Microsoft-Windows-BatteryID가 13인 이벤트 가 있는 ETW 공급자 가 있습니다 BatteryPercentRemaining. 다음을 사용하는 프로젝트를 코딩할 수 있습니다.추적이벤트만들기 위해실시간 청취자Microsoft-Windows-Battery공급자의 경우. 이벤트에는 RemainingPercentage상태를 표시하고 PercentageChange변경 사항을 확인하는 항목이 있습니다.

여기에 이미지 설명을 입력하세요

-1이 이벤트와 에 대한 변경 사항이 확인되면 PercentageChange원하는 프로그램을 실행하세요.

답변3

좋습니다. 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의 답변에 이 수정 사항을 제안했지만 승인되지 않은 이유를 모르겠습니다.

답변4

배터리 잔량을 확인하는 훨씬 쉬운 방법이 있습니다. 탐색 영역에서 배터리 아이콘 위에 마우스를 올려 놓으면 백분율이 표시됩니다.

관련 정보