Friday, February 11, 2011

Easy RDP 6.0 from WinPE 3.0 (Simple Boot WinPE straight to RDP)

I've had a large break from blogging over the past year and thought this would be a good way to get back into the swing of things.

Easily being able to run RDP 6.0 (mstsc) from within a WinPE boot disk has several uses. Either adding the ability to an already setup PE environment (SCCM boot image), or even creating a custom engineer PE disk specific to a corporate environment. For me the really attractive use is very small (around 150MB) WinPE 3.0 install (based on Windows 7) that automatically boots to an RDP session.
Why RDP 6.0 instead of 7.0? Simply because I couldn't get 7.0 working in the stock WinPE environment. That didn't bother me too much though as none of my needs requires any more than version 6.0.

Requirements

  • WAIK - Windows Automated Installation Kit (1.7GB download)
    • Get it from Microsoft or here Google if the first link is broken
    • Windows 7/2008R2 is required
  • Batch files - These files save a lot of time as a ton of commands are required
    • Available here
    • Or if that doesn't work here is where I got them from. Important stuff starts at post 10. Great directions on how to make the bat files and what they do.
  • RDP Files - mstsc.exe, mstscax.dll, mstsc.exe.mui and mstscax.dll.mui (the last two sit in a folder called en-US)
    • Extract it from the installer for XP or 2003, or simple grab them from an existing (up to date) install. They are all located in C:\Windows\System32\ and C:\Windows\System32\en-US\
  • Sleep.exe
  • VirtualBox is free and handy to test your build (and to get the mstsc files). Most people trying to make a custom PE build would probably know about virtual box and its alternatives, however if you don't you should give it a go.

So first off install WAIK. Install to the default directories otherwise the batch files wont work. Unzip the batch files somewhere that will be easy to get to from the command prompt, I’m using C:\PE Tools\.

Start running the batch files and run them administratively (right click on the batch file, Run as administrator). 1-MakePE Directory.bat creates the needed folders and copies the necessary files from the WAIK install. 2-Mount.bat mounts the stock WinPE image to the directory C:\PE\winpe_x86\mount.

Continue onto the 3-Packages.bat, it includes some handy components to the image. 4-Drivers.bat and 5-Additions.bat are optional and I wont go into them right now. Open each of them in notepad to see a description of what they do.

Now we need to copy over the mstsc files and create an auto loading script. Copy mstsc.exe and mstscax.dll to C:\PE\winpe_x86\mount\Windows\System32, and copy mstsc.exe.mui and mstscax.dll.mui to C:\PE\winpe_x86\mount\Windows\System32\en-US. Lastly create a folder called Tools in C:\PE\winpe_x86\mount\ and dump Sleep.exe in it. Using Sleep.exe just helps make sure the network card is up and has obtained an IP.

Now launch notepad and create a file containing the following.

[LaunchApps]
%SYSTEMDRIVE%\Windows\System32\wpeinit.exe
%SYSTEMDRIVE%\Tools\sleep.exe, "10"
%SYSTEMDRIVE%\Windows\System32\mstsc.exe, /v:RDS1 /f


RDS1 is my Remote Desktop Services (Terminal Services) server. Either change it to your own or get rid of the /v to stop it automatically connecting to a server. /f is launch in full screen. Call the text document Winpeshl.ini. Save it to a temp directory and then copy it into C:\PE\winpe_x86\mount\Windows\System32.

Finnally, administritivly run 6-Unmount.bat and then 7-MakeISO.bat. If all goes well your new ISO should be located in C:\PE\winpe_x86.

If you have trouble getting the disk to work try adding %SYSTEMDRIVE%\Windows\System32\cmd.exe before %SYSTEMDRIVE%\Windows\System32\mstsc.exe in Winpeshl.ini. It will load a command prompt before the RDP client, giving you a chance to run things like ipconfig.

The most likely cause for the disk to not work properly is missing drivers. WinPE 3.0 is just a very small Windows 7 so if you need to install drivers to get Windows 7 fully working on the same machine you will need to look at integrating the same drivers into the WinPE disk (batch file number 4).

One last note thing. You don't need to store the mstsc files within System32, I just did that because its a little more clean. If you move them elsewhere remember to maintain the folder structure or en-US.

Update: Handy WinPE resource http://blog.brianleejackson.com/deployment-image-servicing-and-management-dism-winpe-3-0-boot-environment

Update: I'm getting a lot of interest in this so I'll try revisit it again soon. 

14 comments:

  1. Jedibyte9:03 am

    hi -
    This works great. Is there a way to re-launch the RDP session if a user logs out of an active session?
    Kindof like a persistent connection? That way all the end user has to do is type in their username and password. The way it is setup now if a user logs out they get a blank winpe screen.
    Thanks in advance.

    ReplyDelete
  2. Thats a good question Jedibyte, one method that comes to mind is adding multiple entries of "%SYSTEMDRIVE%\Windows\System32\mstsc.exe, /v:RDS1 /f" in the Winpeshl.ini, one after the other (a little messy I know). That way whenever one is closed the next will execute.

    It's not the most efficient method, and it will obviously run out at some point.

    Another method is execute a system restart on the next line (via a batch file or something). After mstsc is closed it will hit the next line in Winpeshl.ini, execute the system and the system will loop.

    Maybe combine both methods?

    Not really the answer you were looking for I know, I'll keep thinking about it and update the post in a couple of days. Thanks for the question.

    I've been meaning to download the new RC of Windows Thin PC http://www.microsoft.com/windows/enterprise/solutions/virtualization/products/thinpc.aspx (basically a cut down Windows 7 designed to be used as a thin client), and check out how I can do the same automatic RDP booting with it. It may have a better way as its designed for being used as a remote connector.

    ReplyDelete
  3. iammacgyver9:50 am

    Thats a good question Jedibyte, one method that comes to mind is adding multiple entries of "%SYSTEMDRIVE%\Windows\System32\mstsc.exe, /v:RDS1 /f" in the Winpeshl.ini, one after the other (a little messy I know). That way whenever one is closed the next will execute.

    It's not the most efficient method, and it will obviously run out at some point.

    Another method is execute a system restart on the next line (via a batch file or something). After mstsc is closed it will hit the next line in Winpeshl.ini, execute the system and the system will loop.

    Maybe combine both methods?

    Not really the answer you were looking for I know, I'll keep thinking about it and update the post in a couple of days. Thanks for the question.

    I've been meaning to download the new RC of Windows Thin PC http://www.microsoft.com/windo... (basically a cut down Windows 7 designed to be used as a thin client), and check out how I can do the same automatic RDP booting with it. It may have a better way as its designed for being used as a remote connector.

    ReplyDelete
  4. Could you launch a bat file as one of your apps? if so you could just put the mstsc launch in the batch file that looks like this:

    :_launchRdp
    mstsc.exe /v:rds1 /f
    goto _launchRdp


    when when mstsc closes, it will go to the next line, which makes it go back up to the _launchRDP label, which launches rdp....

    ReplyDelete
  5. iammacgyver1:35 am

    Yeah thats a much cleaner way of looping it. Batch files worked fine on my last test. 

    ReplyDelete
  6. I'll try this out and let you know if it works. Thanks for this great tip about RDP in WinPE!

    ReplyDelete
  7. Awesome work, cheers. 

    ReplyDelete
  8. Francky10:05 pm

    Thanks a lot for that post. On a few pc, we had a very slow boot.wim at winpe booting with PXE, i've found this : http://technet.microsoft.com/en-us/library/cc731245(WS.10).aspx#BKMK_41

    ReplyDelete
  9. Francky10:19 pm

    Need help : from winpe 3.0, the rdp session does not display USB data (like in ms explorer / tsclient / C) despite of the rdp client 6.0 options (devices plug and play) : at launching winpe can read the usb data (with explorer++ for example or dos command line), but once the rdp session is started, we can't access usb data. The copy/paste of file works beetween winpe and rdp session, though!  Any idea ?

    ReplyDelete
  10. Msiple4:55 am

    When attempting to run the last batch file I get the error that 'oscdimg' is not recognized as an internal or external command??? Any ideas as to why?

    Thank you,

    msiple

    ReplyDelete
  11. Msiple6:10 am

    I fixed it.

    ReplyDelete
  12. I have a much better / faster solution: I can literally take a usb stick and use it to boot straight into RDP within 10 seconds... a CD takes about 18 seconds and through PXE right in between... using a small linux footprint and RDP 7 compliant viewer that outperforms RDP on a Windows box... I'm not kidding.

    ReplyDelete
  13. Share a link or a product name Raymond, sounds like something everyone would like to know. 

    ReplyDelete
  14. Can anyone share the finished product? Is it an ISO file or can it be installed over an hard disk and be booted using a PXE.

    ReplyDelete