Passing Username and Passwords to Remote Desktop (RDP) Automatically
In the past I've tended to use the rdp ocx controls and embed them into a web page. This allows you to pass in a username and password to get the RDP client to connect with. Unfortunately, the MSTSC.EXE program within Windows doesn't have any parameter options to pass in a username and password. therefore, you end up entering the command to connect, and then having to type in the username and password (*sigh*)
Fortunately, help is at hand, and it comes in the form of cmdkey.exe. This is built into Windows from Vista onwards, but if you're using XP, you can download it, have a quick google for it. Now, what cmdkey does is allow you to edit the stored credentials repository on your computer within the session that you are currently in. When MSTSC (RDP) connects to a remote computer it checks this repository to see if it has any matching credentials for the server it's talking to and then attempts to use them, if they are valid, you'll log straight into the desktop, excellent!
So, to wrap this all up neatly, here's a powershell function I wrote to do the connection for you. Just pass in a server name, user name and password and you're away...
Function Open-RDPSession($Server,$User,$Password) { cmdkey /generic:TERMSRV/$server /user:$user /pass:$Password mstsc /v:$Server }
Pretty simple, but it saves you having to remember the syntax!



