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


  1. Posts : 244
    win7pro 64bit
       #1

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


    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


  2. Posts : 2,468
    Windows 7 Ultimate x64
       #2

    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


 

  Related Discussions
Our Sites
Site Links
About Us
Windows 7 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 7" and related materials are trademarks of Microsoft Corp.

© Designer Media Ltd
All times are GMT -5. The time now is 19:21.
Find Us