Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question
@douglaslps Mmm, you should still see the prompt if you unlock the station. At least i tried it here with cmd.exe. If i put that in a on lock workstation and unlock it the cmd.exe is still visible. What user-level did you use? "run only as user is logged on" and not "run with highest priv." and not "hidden"? BTW You should remove the Is it possible to stop the task automatically when I unlock? from your question. If you stop the task automatically it will disappear. – Rik Dec 20 '13 at 11:45
CMD remains visible for me when I log off and on... – Dave Dec 20 '13 at 11:46
Should I run cmd.exe instead of myApp.exe directly? How can I pass myApp as argument to cmd.exe? – douglaslps Dec 20 '13 at 11:48
@rik It is run only as user is logged on and not hidden. – douglaslps Dec 20 '13 at 11:49
@douglaslps No need for a bounty. If you're happy with the answer you can upvote and accept it. – Rik Dec 20 '13 at 12:43
up vote 2 down vote accepted

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
share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .