How to show command-line app started by Windows Task Scheduler?

08
2014-06
  • douglaslps

    I have created a task on Windows Task Scheduler to run a command-line app everytime I lock this machine. It works like a charm.

    My question is: Is it possible to see the Command Prompt window when I unlock?

    Note: This command line app will never finish by itself. It has to be stopped manually.

  • Answers
  • Rik

    We were not exactly sure about the behavior of myApp.exe.

    When starting a cmd.exe and execute myApp.exe, if it directly returns to the C-prompt, it is a "background" app. (i.e. it goes directly to the background). In that case, if you use myApp.exe directly in the Task-scheduler, there is no prompt to return to. (That appears to be the case here)

    You can keep the prompt open if you start cmd.exe in the Task-Scheduler. You can do that by putting cmd.exe in the run-line-box and /K myApp.exe in the parameter-box. You will be returned to the C-prompt after unlocking. In that prompt you can use TASKKILL /F /IM myApp.exe.exe /T to kill myApp.exe (or if the myApp.exe has a kill-switch, use that).

    For others using an app which doesn't return to the C-prompt:

    If the myApp.exe does have output in cmd.exe and does not return to the C-prompt you can use /C myApp.exe. Because myApp.exe will keep the prompt open. A Ctrl+C will likely terminate myApp.exe and also exit the prompt.

    If /K was used in this case you will be returned to the C-prompt (having to do an extra exit-command to exit the prompt).

    Note for CMD.EXE:

    /C      Carries out the command specified by string and then terminates
    /K      Carries out the command specified by string but remains
    

  • Related Question

    windows 7 - How to schedule a task for sleep/hibernate
  • Andrew Redd

    Possible Duplicate:
    Is there any way to execute something when closing the laptop's lid?

    I have a task that I want to run right before my computer sleeps or hibernates. Is there a way to schedule a task for this in the Windows 7 task scheduler?

    The closest that I can see is for on locking the workstation, and this works as a surrogate, but I really don't want it to run on locking unless it is also sleeping/hibernating. Is there a way to schedule for an event like this?


  • Related Answers
  • jcrawfordor

    I think your best bet is to configure the task to shut down or hibernate your computer when it finishes, and then start the task directly instead of stopping your computer. For example, write a batch file that runs the process and then shuts down the machine, and then run that batch file.

  • Andrew Redd

    Found the answer in this question which sites a technet article. The Jist of it is that no the windows 7 is restricted to the list given, but you can attach a task to the sleep/hibernate/shutdown events through the task scheduler. Schedule with the trigger as a log event. For sleep use; Log= System, Source= Kernel-Power, Event ID= 42. And for shutdown System/Security/513.