Schedule ONE-TIME task with "schtasks" at next reboot?

pstein

New member
Member
VIP
Local time
11:25 AM
Messages
244
As you know users can setup a task to be run at startup with the built-in task scheduler "schtasks" with

schtasks /sc ONSTART ... /TR ...

However this command syntax triggers the task at EVERY BOOT time.
How do I setup (from command line and not through GUI!!!) a ONE-TIME task?

For simplicity lets assume I want to run chkdsk for partition E: ONCE at next reboot.

How can I achieve this with "schtasks" built-in command?

I don't want to specify a certain time because it varies from time to time and computer to computer and exacty boot time cannot be specified.

Peter
 

My Computer My Computer

Computer type
PC/Desktop
OS
win7pro 64bit
Not tried it, but quickly seeing the help I can think of two ways for that.

/Z modifier says that it marks the task for deletion after the next execution (not completely sure, but it might work for auto-deleting it after running).
Another option could be to modify the program pointed to /TR to a bat file instead. It will first run the original program and then invoke schtasks again to delete the task, effectively running it only once.

Other possibilities without involving the task scheduler could be to use the registry key specifically designed for this. HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce and HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\RunOnce can point to any programs that are run at login of either every user or a particular one, but then autodeleted by the system itself without further intervention required (installers sometimes drop cleanup routines to perform after reboot.
Note that the registry option is not executed at system startup, but at user login instead.
 

My Computer My Computer

Computer type
Laptop
Computer Manufacturer/Model Number
Toshiba Sattelite A665-S6092
OS
Windows 7 Ultimate x64
CPU
Intel Core i7-740QM
Memory
8 GB DDR3
Graphics Card(s)
NVIDIA GeForce 330GT
Screen Resolution
1366x768
Hard Drives
Samsung 840 SSD 500GB
1TB USB3 external HD
Cooling
Coolermaster Notepal U3 notebook cooling pad
Internet Speed
3mbps ASDL
Antivirus
ClamWin 0.98.7
Browser
Opera 12.17 x86 (main), Firefox 38 (sec), IE11 (last resort)
  • Like
Reactions: whs
Back
Top