Is it possible (and if so, how) to set up a task (console application) in Server 2008 so that it'll run both when a user is logged in and when no user is logged in, AND - if the user is logged in (either local or via RDP) - have the console appear on the screen while the program is running?

Ie. the program should run under the defined user context and it writes status messages to stdout, which goes to a standard console window. This console window is either shown (if the defined user is currently logged in locally or via RDP), or not shown (but the application is still run).

I have access to the source of the console application, so if it needs some additional code (like specifically opening up a new console window or what have you), then that's not a problem.

At the moment, I can set up the task as "Run only when user is logged on" which will run the application when the user is logged on (local or RDP) and I can then see the status messages, or I can set it up as "Run whether user is logged or not" and no status output is visible - not even if the user is logged on.

link|improve this question
feedback

2 Answers

I don't have Server 2008 to test on but on all previous versions you just run the task as the user who will be logged on. The colsole/GUI will still run when the user is not logged on but will not be visible.

link|improve this answer
That's right - but in Server 2008 they changed it so that it won't show the console window if you have it set to "Run whether user is logged or not" - not even if the user is logged on... – HeartWare Aug 23 '10 at 19:49
feedback

I would approach this slightly differently. I would redirect the console program's output to a log file.

for /f "usebackq tokens=1,2,3,4,5,6,7 delims=/:. " %%a in (`echo %DATE% %TIME%`) do set NOW=%%d%%b%%c_%%e%%f%%g
myprogram.exe > c:\logs\job_%NOW%.log 2>&1
rem if user is logged in, display the file
type c:\logs\job_%NOW%.log

If no one is logged in, then the last 'type' command will be inconsequential. As previously suggested, use the "Run whether user is logged or not" option.

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.