Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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.

share|improve this question

3 Answers 3

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.

share|improve this answer

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.

share|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

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).

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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