echo.
echo.*** Warning! Administrator permissions are not detected! ***
echo.
echo This script requires administrator privileges.
echo.
echo To do this, right-click this script, and then select 'Run as administrator'.
echo.
echo Press any key to Exit.
pause >nul
goto :eof
)
for /f "tokens=*" %%G in ('wevtutil.exe el') do (call :do_clear "%%G")
wevtutil.exe cl System
echo.
echo Event Logs have been cleared! ^<Press any key to Exit.^>
pause >nul
goto :eof
if %errorLevel% == 0 (
echo Success: Administrative permissions confirmed.
echo.
) else (
echo Failure: Current permissions inadequate. This script requires administrator privileges.
echo.
echo To do this, right-click this script, and then select 'Run as administrator'.
echo.
echo Press any key to Exit.
pause >nul
goto :eof
)
for /f "tokens=*" %%G in ('wevtutil.exe el') do (call :do_clear "%%G")
wevtutil.exe cl System
echo.
echo Event Logs have been cleared! ^<Press any key to Exit.^>
pause >nul
goto :eof
:do_clear
echo clearing %1
wevtutil.exe cl %1
要想清除日志,需要管理员权限,上面给出了两种检测管理员权限的方法,日志可以用 for 命令遍历,然后调用子程序进行清除。