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.


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.


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.

  • 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

You can make 2 separate Scheduled Tasks, 1 for when logged on and 1 for when not logged on. In the General tab there's an option to Run only while logged on OR to Run whether logged on or not.

Then for the task to be run when not logged in: If the server has a log off timer (i.e. after 10 minutes of idle) you can set up Conditions to Start the task only if the computer is idle for X minutes after 10 minutes of idle time (when it's logged off due to inactivity) and Stop if the computer ceases to be idle (when you log back in).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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