Friday, February 10, 2006

 

RDP Auto logon

EMC recently introduced Free VMware Server - http://www.vmware.com/news/releases/server_beta.html. The server allows to run multiple virtual machines on a single box.

I think the news is really welcome among developers. Now even smallest dev shops are equipped with robust and powerful platform for application development and testing. I expect more and better tools for both Microsoft Windows and Linux to come from ISVs in the near future.

Being excited about the news, I was playing with VMware COM API in an attempt to create an application useful for my colleagues and educational for myself. The application I created uses a combination of VMware, sockets and Windows APIs to monitor and backup the VMware Server. During this exercise I came across a couple of issues that needed to be solved. Among other things there was a need to resolve MAC address to IPs and to automatically run terminal client and connect/logon to a remote IP. Resolving MAC to IP was challenging enough to deserve a separate post.

To my surprise, the second problem was not as easy as I expected either. I thought simply executing native Windows Remote Connection client (mstsc.exe) with proper command line parameters will do the job. Unfortunately mstsc does not allow including user id and password in the command line. Suggestions I found on the internet (like use other terminal clients) were not helpful. See more details in the end of this posting. One of the possible solutions was to reverse engineer the way Microsoft hashes the password before saving it in a RDP file and use the same algorithm to create the file. But there was a simpler solution. The solution that finally came to my mind is to start native client and send it required parameters through SendMessage (…,WM_SETTEXT,...) API.

As the result, I created a simple utility that implements this method to script terminal client connections. The utility takes arguments from the command line, passes some of them to the native mstsc and sends additional parameters through the SendMessage API.

This free utility can be downloaded here. It does not require installation and works on Microsoft Windows XP and Microsoft Windows 2003 server. Please read readme.rtf for usage information. I hope the utility will be of help for those who’d like to script Remote Desktop Connection in Microsoft Windows XP and/or Microsoft Windows Server 2003.

Comments:


Andrei, the aplicattion works perfectly in Windows 2003-EN, but I being of Argentine I use windows xp in Spanish. On this platform autordp does not work, only it shows me the window of remote destop in order that I enter the parameters manually. Did you have a way to fix it ? Thanks
 


The program is very usefull. It would be even more usefull if there was a possibility to specify an application.
 


Would you please make a change so that it loads the rdp file ..\My Documents\default.rep if one isn't specified on the command line.

Robert (at the ip this came from)
 


Hi Andrei. I just discovered your blog, so this is a little late from your post here, but it's still useful.

What I've done to get the IP address for a running VM is break it into a 3 step process.

1. Get .VMX file (from vmrun list)
2. Get the MAC address from the .VMX file (scan for ethnet0.generatedAddress)
3. Read the VMWare DHCP leases file to match the MAC address with the IP address. I use the Text::DHCPparse perl module for this.

I'm not sure where VMWare stores the leases file on Windows (I'll have to check with some of my co-workers), but on Linux it's stored as /etc/vmware/vmnet8/dhcpd/dhcpd.leases

The vmnet8 might be different if you have networking configured differently.
 


Hi Andrei,

I was very happy as i found your tool. I tried hard, to do hack MS hashing of password, to generate a .rdp-file, but i didnt get it to work.
Your solution is much easier and works well. But unfortunately it works only with an English Windows XP installation. It would be great, if it runs also on German OS. Do you think thats possible for you?
 


Wow! I didn’t realize the comments to the blog are moderated:) I'll change it to unmoderated as soon as I find a way. Sorry for not being responsive so far and many thanks for the feedback.

I’ll sure look into the localized Windows issue and hope it won’t take long to fix it.

Chris, thanks for the great tip! I’ll check your blog right away.

I’ll also look into Robert’s comment. (Robert, did you actually mean default.rdp?)
 


Just to let everyone know:
I’ve built UNICODE version (plus fixed some bugs), but don’t want to put it on the web yet. I tested it on Russian XP,SP2 and it does work now. If anyone wants to try it out, here is the link:
http://www.abinsight.com/tools/temp/autordp.exe
Not the official release as I’m yet to implement other suggestions.
Thanks again for your feedback!
 


Re default.rdp, yup it's the rdp file, just like mstsc normally does.

Robert (not at the ip this came from)
 


Thanks for a great product!
 


Hi Andrei, great tool. Only problem i have is that after a disconnect the options are shown and not closed. Are you planning to make a function to close the entire progam?
 


Re: possibility to specify an application

I don't like the idea of having too many parameters in the command line. I suggest you manipulate the .rdp file directly to add an application to it. Here is one example how to do it (it is aasumed that the cmd file is not unicode while rdp is) from a batch file (sorry for the formatting):


rem Use myrdp.rdp.bak as atemplate

copy "myrdp.rdp.bak" "myrdp.rdp"

cmd /u /c echo alternate shell:s:%~1>>"myrdp.rdp"

cmd /u /c echo shell working directory:s:%~1\..\>>"myrdp.rdp"

rem notepad "myrdp.rdp"

rem start autordp with appropriate parameters here


P.S. myrdp.rdp.bak is used as a template, but one has to make sure it does not define "alternate shell" and "shell working directory" parameters
 


Re: Options are shown after disconnect

Hm. I cannot repro this. On my machines everything is closed after I logout or close the remote session. If anyone else has similar behavior - could you please post OS/SP/mstsc version numbers? The version of the mstsc can be found in its properies dialog (navigate to system32\mstsc.exe and do Alt-Enter)

Thanks,
Andrei
 


Re: default.rdp

I do have a build where autordp uses default.rdp file. The only thing I'm unsure about is whether or not it will work on Windows 2000 (Shell API is used). I don’t have W2K at the moment, but if you feel like this feature is nice to have and are willing to test it, please contact me: abaronov at amustsoft dot com and I’ll send you the build.

Thanks,
Andrei
 


I've been successfully using autordp for the past 6 months, but with the (somewhat) recent update of mstsc to version 6.0, I'm finding that autordp is not properly passing the username and password. Am I doing something wrong? Has anyone successfully got autordp to work with mstsc 6.0?
 


First time user on Windows 2003 server with the new mstsc.exe 6.0.6000.16386 and it doesn't seem to be working. I think the new version is preventing the passing of the parameters. MIght consider rolling back the mstsc.exe version unless a fix is upcoming. thanx
 


Yep, the tool does not work with mstsc 6. I’ll try to come up with an update hopefully these weekends. Stay tuned!
Thanks,
Andrei
 


The beta that is compatible with mstsc 6 is available here:

http://abaronov.blogspot.com/2007/02/rdp-auto-logon-20-beta-1.html
 


Hi, Andrei. Whats about Windows CE?
Exist CE version RDP Autologon?
 


if it doesnt work try this hash generator:
http://www.remkoweijnen.nl/blog/2007/10/18/how-rdp-passwords-are-encrypted
 


You just saved my life man! That's exactly what I needed!

Thanx a lot! Nice job!
 


Can you give some details on how you accomplished this? I'm trying to do an experiment and avoid Terminal Services timeouts by sending some data to the window to trick the idle timer without focusing the window. But nothing seems to works. What window class did you target? Does the window have to be focused?
 
Post a Comment



<< Home

This page is powered by Blogger. Isn't yours?