0

I'm in need a bat file to clear Event Viewer logs and re-boot computer...or help in modifying the ones I already have so that once ran from an administrator prompt, it'd clear the logs...and reboot the computer.

Any help would be appreciated.

0

2 Answers 2

0

Use the wevtutil commnad in your batch script.

To clear a specific log, you must first know its name. To see a list of Event Logs, run:

wevtutil el > Loglist.txt

Find the name of the log you want to clear and use it on the command.

For example, to clear the Application log, use the following command:

wevtutil cl Application

To reboot, use the shutdown command:

shutdown -r

This requires administrator permissions.

1
  • Appreciate the input, I already have three scripts that do these individually.
    – PB-1
    Commented May 9, 2022 at 4:19
0

The following script searches for all Event logs, clears them, then reboots on success. It must be run as Admin.

@echo off
FOR /F "tokens=1,2*" %%V IN ('bcdedit') DO SET adminTest=%%V
IF (%adminTest%)==(Access) goto noAdmin
FOR /F "tokens=*" %%G in ('wevtutil.exe el') DO (call :do_clear "%%G")
rem Event Logs have been cleared!
shutdown -r
goto fini
:do_clear
echo clearing %1
wevtutil.exe cl %1
goto :eof
:noAdmin
echo You must run this script as an Administrator!
pause
echo.
:fini
4
  • The script for clearing ALL Event logs and rebooting works for my need, thanks. I did notice that b4 rebooting, there is a notification much like when one receives a remote shutdown from a network computer. That is due to the 'shutdown -r' instruction, correct?
    – PB-1
    Commented May 9, 2022 at 4:03
  • There is also a delay of about 45 secs to a minute before the computer actually reboots. Is there a way to reboot, immediately without waiting to allotted 45 secs to a minute?
    – PB-1
    Commented May 9, 2022 at 4:16
  • Or to cut the wait time to a 20 sec delay? I ask because when I send remote shutdowns using a third party program to any one of me 7 rigs on my home network, there is an option to delay or speedup sent instructions by xx -xx seconds. For curiosity sake only, the script supplied works good as is, indeed.
    – PB-1
    Commented May 9, 2022 at 4:17
  • shutdown /r /t 0 reboots with no delay, shutdown /s /t 0 shuts down with no delay. See docs.microsoft.com/en-us/windows-server/administration/… for shutdown command-line options. Noe that in most versions of Windows, hyphen may be used instead of forward-slash. Commented May 9, 2022 at 23:32

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .