Computer Hope

Microsoft => Microsoft DOS => Topic started by: Hackoo on November 09, 2017, 04:53:33 PM

Title: Batch file to show or delete a numbered task names
Post by: Hackoo on November 09, 2017, 04:53:33 PM
Hi  ;)
I need a little help to improve my new batch to show or delete a numbered task names
The code below works fine if the task name does not contains a space  :D
So i'm looking how can i modify it to read a task name with a space   ???
Thank you for any help  :-*
Code: [Select]
@echo off
Title Delete Tasks with their time tasks execution by Hackoo 2017
Mode 90,30 & color 0A
:Menu
cls & echo(
echo Type the time with this format "hh:mm" to show or delete for scheduled Tasks
set /a "count=0"
set /p "strTime="
cls & echo(
Setlocal EnableDelayedExpansion
@for /f "tokens=1 delims= " %%a in ('schtasks /query ^| find /I "%strTime%"') do (
set /a "Count+=1"
set "TaskName[!Count!]=%%a"
)
Rem Display numbered Task Names
@for /L %%i in (1,1,%Count%) do (
set "msg=[%%i] - !TaskName[%%i]!"
echo !msg!
)
echo(
Rem Asking the user if he wants to delete or not the numbered task names
echo Type the number of the task to delete !
set /p "Input="
@for /L %%i in (1,1,%Count%) Do (
    If "%INPUT%" EQU "%%i" (
schtasks /delete /tn "!TaskName[%%i]!"
)
)
echo(
echo Type any key to show and delete another task !
Pause>nul
Goto Menu
Title: Re: Batch file to show or delete a numbered task names
Post by: Squashman on November 09, 2017, 06:40:33 PM
Answered on DosTips (http://www.dostips.com/forum/viewtopic.php?f=3&t=8223#p54636)
Title: Re: Batch file to show or delete a numbered task names
Post by: Hackoo on November 09, 2017, 07:18:07 PM
Answered on DosTips (http://www.dostips.com/forum/viewtopic.php?f=3&t=8223#p54636)
Thank you very much for your help  ;)