How to force a process to run on the console on Windows 2003 server?
I have a funky situation where a certain batch-type application works correctly when run on the console (via RDP or when physically logged on to the box), but doesn't work correctly when run via RDP on a non-console session or, for that matter, when executed by the Windows Task Scheduler.
I know how to determine 开发者_开发百科programmatically if my process is running on the console or not by checking the SESSIONNAME environment variable.
My question is, if I determine that I'm NOT running on the console, I want to either switch to the console (seems unlikely due to window station restrictions), or more likely, re-launch the process but force it to run on the console session.
It's really an issue for processes that get kicked off via Windows Task Scheduler since they don't seem to run on the console.
I think you create the process in the console session via a combination of WTSGetActiveConsoleSessionId, WTSQueryUserToken, and CreateProcessAsUser.
精彩评论