The Test Agent can run in either Service or Process mode. For the Coded UI test, you need to run it in a process mode (because it needs to be in the same windows session). But when you log into VM, with Remote Desktop, and close it, the Desktop of the target machine stays locked and tests cannot proceed. And unless you log in, there is no active session and the test controller doesn't even get started.
There are 2 ways to keep an active desktop that I know of:
- (recommended) Run AutoLogOn.exe from Sysinternals suite (can be found at http://live.sysinternals.com/). It will automatically log in with a specified user then the machine starts, and keep the desktop active.
- Keep a remote desktop in a non minimized window active. There are few applications that you can find that can keep multiple remote desktops open, and keeping it connected should do the trick.