A
A
Alexander2019-03-21 11:01:27
cmd/bat
Alexander, 2019-03-21 11:01:27

Why is the line in the bat file not being executed?

I found a command that works with a bang in the command line on behalf of the administrator:

for /F "tokens=*" %1 in ('wevtutil.exe el') DO wevtutil.exe cl "%1"

This miracle line cleans all (well, almost) Windows logs.
But if you put it in a cmd or bat file and run it as administrator, it does not work.
The window closes immediately.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
res2001, 2019-03-21
@Dem0lisher

1. replace %1 with %a, i.e. number to letter. In batch files, digital variables are command line parameters passed to the batch file. You must use literal variables in loops.
2. In the bat file, use 2 % signs before the variable: %%a

I
iluwa, 2019-03-21
@iluwa

when you run as administrator - the working folder for the bat file is "C:\Windows\System32", so there is no wevtutil.exe there.
Add cd /d "%~dp0" to the beginning of the batch file and you will be happy (if there is wevtutil.exe next to the batch file)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question