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

4

1

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.

douglaslps

Posted 2013-12-20T09:59:01.997

Reputation: 1 240

@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 – 2013-12-20T11:45:31.953

CMD remains visible for me when I log off and on... – Dave – 2013-12-20T11:46:24.637

Should I run cmd.exe instead of myApp.exe directly? How can I pass myApp as argument to cmd.exe? – douglaslps – 2013-12-20T11:48:12.823

1@rik It is run only as user is logged on and not hidden. – douglaslps – 2013-12-20T11:49:45.360

@douglaslps Weird. Are you sure your app is still running? Could you see under which user (in taskmanager)? And could you create a new one with just cmd.exe to see if that one stays on screen after unlocking? If running myApp.exe gives you a prompt it should stay after locking and unlocking so cmd.exe wouldn't be needed for starting it in task scheduler. But you should test if it gives you a prompt when running it. – Rik – 2013-12-20T11:53:29.777

What is MyApp.exe? I thought this issue was with Command Prompt? If you're using another program to launch the command prompt then there could be logic inside which accounts for the behaviour – Dave – 2013-12-20T11:55:16.033

Maybe I'm having a hard time to explain what myApp.exe is. If I start a Cmd I can use it to lauch MyApp.exe. It is just a command-line mode app. @Rik yes, I know the app is still running because the CPU is being fully used and and the task status is shown as Running. – douglaslps – 2013-12-20T11:59:28.943

@douglaslps If you start myApp.exe directly from the Windows Explorer (so not via cmd.exe) do you still get the prompt (black cmd-screen)? If not then you need to start myApp.exe with cmd.exe in your task scheduler. You can do that by putting cmd.exe in the run-line-box and /C myApp.exe in the parameter-box. – Rik – 2013-12-20T12:03:02.263

@douglaslps If, on the other hand, in the cmd.exe you start myApp.exe and you get a C-prompt directly back, the myApp.exe is not a program that echos anything back to the prompt and goes directly in the background. In that case there is no need to go back to that prompt because there is nothing to see. – Rik – 2013-12-20T12:05:28.990

@DaveRook MyApp.exe has a endless loop so it will keep running until I kill it. I want both the Command Prompt visible and MyApp.exe running on it. – douglaslps – 2013-12-20T12:06:48.723

@Rik I think you nailled it. I need to start cmd.exe and use myApp.exe as a parameter. I would like to thank you for that. I will offer a bounty for this question (I can only do it in 2 days) so please post your answer and I will reward you. BTW, I think /C will stop the terminal while /K will keep it running. – douglaslps – 2013-12-20T12:09:27.687

@DaveRook yes. But I know MyApp.exe is still running. – douglaslps – 2013-12-20T12:11:51.023

1@douglaslps No need for a bounty. If you're happy with the answer you can upvote and accept it. – Rik – 2013-12-20T12:43:38.390

Answers

2

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

Rik

Posted 2013-12-20T09:59:01.997

Reputation: 11 800