Y
Y
Yan2021-03-11 01:17:19
cmd/bat
Yan, 2021-03-11 01:17:19

How to add a variable instead of a number in a batch file?

Here are my pathetic attempts

for /L %%i IN (1,1,10000000000) do call :doschtasks %i
goto :EOF
:doschtasks
set FN=%i
schtasks /delete /tn "Opera GX scheduled Autoupdate %FN%" /f
pause


The task is to remove the task "Opera GX scheduled Autoupdate 1615341492"
the last numbers always change,

you need to either batch brute
from 1 to 10kkk
or come up with something cooler

ideas?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
W
wisgest, 2021-03-11
@Slayer_nn

The following lines have been corrected:

for /L %%i IN (1,1,10000000000) do call :doschtasks %%i

set FN=%1

although all this can be done in one line without CALL.
But, in order not to sort through all the numbers, you can try to process the output schtasks /queryto get the names of the current jobs:
for /f "usebackq delims=" %%L in (`schtasks /query /fo csv /nh^|find "Opera GX scheduled Autoupdate "`) do  call :sub %%L
exit /b

:sub
schtasks /delete /tn %1 /f

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question