11

On my Windows 7 machine I can run something like:

schtasks.exe /Change /TN "MyTaskName" /Disable

But /Disable doesn't seem to be available in Windows XP - is there any way of disabling it from the command line?

John Sibly
  • 387
  • 3
  • 6
  • 8

3 Answers3

8

The /disable switch is only a feature of Vista/7/2008R2/2012.

You can simply rename the task .job file to "disable" it.

schtasks /Create /SC HOURLY /TN "TEST TASK" /TR notepad
schtasks

TaskName                             Next Run Time            Status
==================================== ======================== ===============
TEST TASK                            09:45:00, 7/26/2010

move "C:\WINDOWS\Tasks\TEST TASK.job" "C:\WINDOWS\Tasks\TEST TASK.bak"
schtasks
INFO: There are no scheduled tasks present in the system.

In order to "enable" the task rename the .bak file to .job:

schtasks
INFO: There are no scheduled tasks present in the system.

move "C:\WINDOWS\Tasks\TEST TASK.bak" "C:\WINDOWS\Tasks\TEST TASK.job"
schtasks

TaskName                             Next Run Time            Status
==================================== ======================== ===============
TEST TASK                            09:45:00, 7/26/2010
TechFanDan
  • 297
  • 1
  • 6
  • 20
jscott
  • 24,484
  • 8
  • 79
  • 100
  • Good idea. However I'd really like it to actually appear as disabled in Task scheduler, so I can enable it again at some point in the future. Normally you could just set it to "Run Once" and set a specific time, but this particular script we need to run on login, and then disable itself. – John Sibly Jul 26 '10 at 14:19
  • 4
    @John: Updated my answer to show "enabling" example. Barring that option, you can copy `C:\Windows\System32\schtasks.exe` binary from a 2003+ install. Place this binary on the XP machine and call it using its explicit path. I have just successfully tested disabling a task created with the XP `schtasks` using the 2003 `schtasks`. – jscott Jul 26 '10 at 14:55
  • Thanks for your answers - I'm going to use the Win2003 workaround as this fits our situation better. But the renaming idea may also come in handy at some point too – John Sibly Jul 26 '10 at 15:54
2

In order to acheive the run-once behaviour, you could always just code a 'wrapper' bat script that checks for a lock file.

Create the lock file on first run, and every there after the wrapper script will just exit if it finds the lock file:

if exist Lock.file goto :eof
Michael
  • 71
  • 3
1

You have to run this code:

SCHTASKS /Change /TN "\yourFolder\yourTask" /Disable
Andrew Schulman
  • 8,811
  • 21
  • 32
  • 47