bat批量删除指定的任务计划?

批处理如何删除包含某些字符的任务计划?

已知系统任务计划中有“UpdateTask123456”,其中的123456是随机数字,如何通过批处理删除它。
我用了:schtasks /delete /tn "UpdateTask*" /f  删除不了,请大神们指点。

-----------------------------------------------------------------------------------------

参考:
schtasks /query + schtasks /delete
http://bbs.bathome.net/thread-34301-1-1.html#pid162504

-----------------------------------------------------------------------------------------

@echo off
chcp 437>nul
for /f "tokens=1*" %%a in ('schtasks /query /fo list^|findstr /ibrc:"TaskName: *\\jf"') do (
        for /f "tokens=* delims=\" %%c in ("%%b") do (
                schtasks /delete /tn "%%c" /f
        )
)
pause

在win10中,参考贴子中的批处理,测试没运行,不知那里不对,请高手指点一下
比如删下面的,后面的一串xxxxxx是随机的
schtasks /delete /TN "MicrosoftEdgeUpdateTaskMachineCorexxxxxxxxxxxxxxxxxx" /f

-----------------------------------------------------------------------------------------

chcp 437>nul
for /f "tokens=1*" %%a in ('schtasks /query /fo list^|findstr /ibrc:"TaskName: *"') do (
        for /f "tokens=* delims=\" %%c in ("%%b") do (
                @echo "%%c"
        )
)

其实就是没有过滤出来的问题,先改成上面这样的,可以完全显示列出所有任务了,但过滤出想要的不会搞了,findstr不知能不能搞出来

-----------------------------------------------------------------------------------------

以下代码是预览版,确认与所删任务名相同后,抹去代码第2行尾部的 echo, 即可改为实际删除版...

 

@echo off &for /f "tokens=1* delims=: " %%a in (
' schtasks /query /fo list^|findstr /irc:".*MicrosoftEdgeUpdateTaskMachineCore.*" ') do (echo,schtasks /delete /tn "%%b" /f)
pause&exit/b

同法处理一楼示例的代码如下...

@echo off &for /f "tokens=1* delims=: " %%a in (
' schtasks /query /fo list^|findstr /irc:".*UpdateTask.*" ') do (echo,schtasks /delete /tn "%%b" /f)
pause&exit/b

补充说明》以上代码仅用于目标任务所含关键词唯一的情况...

-----------------------------------------------------------------------------------------

出处:http://www.bathome.net/viewthread.php?tid=69282

posted on 2024-07-10 16:35  jack_Meng  阅读(2)  评论(0编辑  收藏  举报

导航