Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Windows API
  4. How to set the rule "Do not start new instance" in Task scheduler's settings using command line

How to set the rule "Do not start new instance" in Task scheduler's settings using command line

Scheduled Pinned Locked Moved Windows API
tutorial
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    KTTransfer
    wrote on last edited by
    #1

    Hi, OS: Windows Vista I have created the scheduled task through command line to invoke one exe. Now I want to make that schedule run my exe only once, i mean only instance should run. If there are no instances then it should start one. In task scheduler, for task properties, in settings tab i have "if the task is already running, then the following rule applied" option, where i can set "Do not start a new instance". I want to set the rule in Task Scheduler's settings as "Do not start a new instance". But through command line how to set the same. Thanks in advnace. Regards, KTTransfer.

    L 1 Reply Last reply
    0
    • K KTTransfer

      Hi, OS: Windows Vista I have created the scheduled task through command line to invoke one exe. Now I want to make that schedule run my exe only once, i mean only instance should run. If there are no instances then it should start one. In task scheduler, for task properties, in settings tab i have "if the task is already running, then the following rule applied" option, where i can set "Do not start a new instance". I want to set the rule in Task Scheduler's settings as "Do not start a new instance". But through command line how to set the same. Thanks in advnace. Regards, KTTransfer.

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      Hi, I would suggest conditionally starting your scheduled task from a batch file. You can check to see if your task is already running with something like:@echo off SCHTASKS | FINDSTR "Running" | FINDSTR "YOUR TASK NAME" if %ERRORLEVEL% == 1 goto not_running if %ERRORLEVEL% == 0 goto is_running :not_running start %comspec% /c "mode 32,3&title Info&color 1e&echo.&echo.That task is not running.&echo.&pause>NUL" goto end :is_running start %comspec% /c "mode 32,3&title Info&color 1e&echo.&echo.Task is running.&echo.&pause>NUL" goto end :end
      Best Wishes, -David Delaune

      K 1 Reply Last reply
      0
      • L Lost User

        Hi, I would suggest conditionally starting your scheduled task from a batch file. You can check to see if your task is already running with something like:@echo off SCHTASKS | FINDSTR "Running" | FINDSTR "YOUR TASK NAME" if %ERRORLEVEL% == 1 goto not_running if %ERRORLEVEL% == 0 goto is_running :not_running start %comspec% /c "mode 32,3&title Info&color 1e&echo.&echo.That task is not running.&echo.&pause>NUL" goto end :is_running start %comspec% /c "mode 32,3&title Info&color 1e&echo.&echo.Task is running.&echo.&pause>NUL" goto end :end
        Best Wishes, -David Delaune

        K Offline
        K Offline
        KTTransfer
        wrote on last edited by
        #3

        Hi David, Thank you , it helped me a lot. One more Query I have: 1st Case: How to make task readonly , I mean user should not modify or delete the particular task in "Task Scheduler" and I want to do this setting using command line. Is there any way? (OR) 2nd Case: I want to check all the tasks in task scheduler, if particular task is not created or deleted by user then I will create one. To check all the tasks present in Task Scheduler, I need to check for OS version and depending upon the OS, path of task scheduler(where tasks are created) will change like: Windows vista: dir /b “%SystemRoot%\system32\Tasks” Windows server 2003: dir /b “%SystemRoot%\Tasks” Windows XP: dir /b “%SystemRoot%\Tasks” Is there any predefined way to do or I need to follow one of the above cases. If you have any clue to implement please let me know. Thanks in advance. Regards, KTTransfer.

        L 1 Reply Last reply
        0
        • K KTTransfer

          Hi David, Thank you , it helped me a lot. One more Query I have: 1st Case: How to make task readonly , I mean user should not modify or delete the particular task in "Task Scheduler" and I want to do this setting using command line. Is there any way? (OR) 2nd Case: I want to check all the tasks in task scheduler, if particular task is not created or deleted by user then I will create one. To check all the tasks present in Task Scheduler, I need to check for OS version and depending upon the OS, path of task scheduler(where tasks are created) will change like: Windows vista: dir /b “%SystemRoot%\system32\Tasks” Windows server 2003: dir /b “%SystemRoot%\Tasks” Windows XP: dir /b “%SystemRoot%\Tasks” Is there any predefined way to do or I need to follow one of the above cases. If you have any clue to implement please let me know. Thanks in advance. Regards, KTTransfer.

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          Hi again, It seems like you need to do a bit of research on NT systems administration. These are some fairly basic systems administration questions. Regarding case 1: Task Scheduler and security[^] How to use Xcacls.exe to modify NTFS permissions[^] Essentially you will need to modify the access control list for the %SYSTEMROOT%\Tasks folder. I would also recommend executing your task under a privileged account such as SYSTEM to avoid being terminated by the user. Regarding case 2: I do not know why Microsoft changed the default task folder location. But you can check if the path exists from your batch file:IF NOT EXIST "%SYSTEMROOT%\Tasks"
          There may be a better way of doing this. Best Wishes, -David Delaune

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups