使用 schtasks 禁用所有任务
Disabling all tasks with schtasks
我需要做一个禁用所有任务的批处理文件,到目前为止我已经得到了这个:
@echo OFF
for /f "tokens=2 delims=:" %%i in ('schtasks /Query /FO LIST ^| findstr "Nombre de tarea:"') do (call :subroutine "%%i")
:subroutine
set TASKNAME=%%i
echo %TASKNAME%:%1
schtasks /change /tn=%TASKNAME%:%1 /disable
GOTO :eof
所以,我对 grep 的使用非常糟糕,已经 2 年没有使用它了,这就是 "findstr" "spits":
%i:" Interactivo/En segundo plano"
%i:" ADMSH-PC"
%i:" \Microsoft\Windows\Windows Media Sharing\UpdateLibrary"
所以我每个任务得到 3 行,而且我只需要 "task name" 作为 tn 属性 而不是整个路径
有help/tips吗?谢谢
如果您要禁用所有任务,那么只停止任务计划程序服务不是更容易吗?
很好,但是如果您想禁用它们,我建议您将脚本放入 vbs 文件中:
您可以使用此代码列出所有任务:
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\" & strComputer & "\root\cimv2")
Set colScheduledJobs = objWMIService.ExecQuery _
("Select * from Win32_ScheduledJob")
For Each objJob in colScheduledJobs
Wscript.Echo "Caption: " & objJob.Caption
Wscript.Echo "Command: " & objJob.Command
Wscript.Echo "Days Of Month: " & objJob.DaysOfMonth
Wscript.Echo "Days Of Week: " & objJob.DaysOfWeek
Wscript.Echo "Description: " & objJob.Description
Wscript.Echo "Elapsed Time: " & objJob.ElapsedTime
Wscript.Echo "Install Date: " & objJob.InstallDate
Wscript.Echo "Interact with Desktop: " & objJob.InteractWithDesktop
Wscript.Echo "Job ID: " & objJob.JobID
Wscript.Echo "Job Status: " & objJob.JobStatus
Wscript.Echo "Name: " & objJob.Name
Wscript.Echo "Notify: " & objJob.Notify
Wscript.Echo "Owner: " & objJob.Owner
Wscript.Echo "Priority: " & objJob.Priority
Wscript.Echo "Run Repeatedly: " & objJob.RunRepeatedly
Wscript.Echo "Start Time: " & objJob.StartTime
Wscript.Echo "Status: " & objJob.Status
Wscript.Echo "Time Submitted: " & objJob.TimeSubmitted
Wscript.Echo "Until Time: " & objJob.UntilTime
Next
获取所有任务的名称和 运行 每个任务的 schtasks /change /tn=%TASKNAME%:%1
/disable。
for /f "tokens=1 delims=," %%a in (
'schtasks /Query /FO csv ^| find /V "Task name" ^| find /V "Disabled"'
) do (
schtasks /change /tn %%a /disable
)
注意:如果您显示此命令的示例“schtasks /Query /FO csv
”,我可以将命令编辑为您的语言环境
为什么要禁用任务?从命令行停止和启动任务计划服务。如果停止在服务中显示为灰色 - 任务计划程序下载 PsTools 和:
运行 作为管理员:
PSEXEC -i -s CMD
在CMD中window:
net stop schedule
准备就绪后:
net start schedule
启用禁用所有计划任务启用禁用所有任务任务计划程序停止变灰
我需要做一个禁用所有任务的批处理文件,到目前为止我已经得到了这个:
@echo OFF
for /f "tokens=2 delims=:" %%i in ('schtasks /Query /FO LIST ^| findstr "Nombre de tarea:"') do (call :subroutine "%%i")
:subroutine
set TASKNAME=%%i
echo %TASKNAME%:%1
schtasks /change /tn=%TASKNAME%:%1 /disable
GOTO :eof
所以,我对 grep 的使用非常糟糕,已经 2 年没有使用它了,这就是 "findstr" "spits":
%i:" Interactivo/En segundo plano"
%i:" ADMSH-PC"
%i:" \Microsoft\Windows\Windows Media Sharing\UpdateLibrary"
所以我每个任务得到 3 行,而且我只需要 "task name" 作为 tn 属性 而不是整个路径
有help/tips吗?谢谢
如果您要禁用所有任务,那么只停止任务计划程序服务不是更容易吗?
很好,但是如果您想禁用它们,我建议您将脚本放入 vbs 文件中:
您可以使用此代码列出所有任务:
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\" & strComputer & "\root\cimv2")
Set colScheduledJobs = objWMIService.ExecQuery _
("Select * from Win32_ScheduledJob")
For Each objJob in colScheduledJobs
Wscript.Echo "Caption: " & objJob.Caption
Wscript.Echo "Command: " & objJob.Command
Wscript.Echo "Days Of Month: " & objJob.DaysOfMonth
Wscript.Echo "Days Of Week: " & objJob.DaysOfWeek
Wscript.Echo "Description: " & objJob.Description
Wscript.Echo "Elapsed Time: " & objJob.ElapsedTime
Wscript.Echo "Install Date: " & objJob.InstallDate
Wscript.Echo "Interact with Desktop: " & objJob.InteractWithDesktop
Wscript.Echo "Job ID: " & objJob.JobID
Wscript.Echo "Job Status: " & objJob.JobStatus
Wscript.Echo "Name: " & objJob.Name
Wscript.Echo "Notify: " & objJob.Notify
Wscript.Echo "Owner: " & objJob.Owner
Wscript.Echo "Priority: " & objJob.Priority
Wscript.Echo "Run Repeatedly: " & objJob.RunRepeatedly
Wscript.Echo "Start Time: " & objJob.StartTime
Wscript.Echo "Status: " & objJob.Status
Wscript.Echo "Time Submitted: " & objJob.TimeSubmitted
Wscript.Echo "Until Time: " & objJob.UntilTime
Next
获取所有任务的名称和 运行 每个任务的 schtasks /change /tn=%TASKNAME%:%1
/disable。
for /f "tokens=1 delims=," %%a in (
'schtasks /Query /FO csv ^| find /V "Task name" ^| find /V "Disabled"'
) do (
schtasks /change /tn %%a /disable
)
注意:如果您显示此命令的示例“schtasks /Query /FO csv
”,我可以将命令编辑为您的语言环境
为什么要禁用任务?从命令行停止和启动任务计划服务。如果停止在服务中显示为灰色 - 任务计划程序下载 PsTools 和:
运行 作为管理员:
PSEXEC -i -s CMD
在CMD中window:
net stop schedule
准备就绪后:
net start schedule
启用禁用所有计划任务启用禁用所有任务任务计划程序停止变灰