@ECHO OFF
:: Check if script is running with administrator privileges
powershell -Command "Start-Process cmd -Verb RunAs -ArgumentList '/c %0 %*' -Wait; exit"
if %ERRORLEVEL% neq 0 (
ECHO.
echo 您需要以管理员身份运行此脚本。
pause
exit /b
)
for /f "tokens=2 delims==" %%i in ('wmic OS Get localdatetime /value') do set timestampOrgin=%%i
ECHO.
set timestamp=%timestampOrgin:~0,8%_%timestampOrgin:~8,6%
ECHO %date% %time% timestamp=%timestamp% (from %date% %time%)
ECHO.
set subDir=ReportHtml
set fileDir=%~dp0%subDir%\
if not exist "%fileDir%" mkdir "%fileDir%"
ECHO %date% %time% fileDir=%fileDir%
ECHO.
set filePathSystemSleepDiagnostics=%fileDir%%timestamp%_SystemSleepDiagnostics.html
ECHO %date% %time% filePathSystemSleepDiagnostics=%filePathSystemSleepDiagnostics%
ECHO.
set filePathSystemPowerReport=%fileDir%%timestamp%_SystemPowerReport.html
ECHO %date% %time% filePathSystemPowerReport=%filePathSystemPowerReport%
ECHO.
set filePathBatteryReport=%fileDir%%timestamp%_BatteryReport.html
ECHO %date% %time% filePathBatteryReport=%filePathBatteryReport%
ECHO.
set filePathEnergyReport=%fileDir%%timestamp%_EnergyReport.html
ECHO %date% %time% filePathEnergyReport=%filePathEnergyReport%
ECHO.
PowerShell -ExecutionPolicy Bypass -Command "& {powercfg.exe /systemsleepdiagnostics /OUTPUT '%filePathSystemSleepDiagnostics%'}"
ECHO.
PowerShell -ExecutionPolicy Bypass -Command "& {powercfg.exe /SLEEPSTUDY /OUTPUT '%filePathSystemPowerReport%'}"
ECHO.
PowerShell -ExecutionPolicy Bypass -Command "& {powercfg.exe /BATTERYREPORT /OUTPUT '%filePathBatteryReport%'}"
ECHO.
PowerShell -ExecutionPolicy Bypass -Command "& {powercfg.exe /energy /OUTPUT '%filePathEnergyReport%'}"
ECHO.
ECHO %date% %time% [任意键关闭...]
pause>nul
@ECHO ON