Something that has been a source of frustration to many IT staff is the lack of support for .NET and PowerShell within Windows PE. Although there are many good reasons why this is not included – memory usage/size of boot images being among the reasons…it is still an unfortunate thing being limited to Win32 .EXEs, VBScript, or AutoIT. Unfortunate because with Microsoft’s promotion of C# .NET and PowerShell for so long, many of us have grown to love the power and simplicity of these frameworks/scripting languages. Having to write utilities for PE in Win32 C++ or VBScript is a serious pain. Every time I have to go back to VBScript/HTAs I cringe, and as much as I love C++ after being pampered so long in .NET there is some frustration whenever I have to use it. So I wanted to come up with a workaround solution until someday we may get proper support.
My first approach was just to try and copy the .NET framework files into my PE image, with a few reg keys. However this method did not succeed. So I needed to find a way to understand what exactly got installed as part of .NET and PowerShell. To assist with this process I decided to use ThinApp. ThinApp is an Application Virtualization solution from VMWare that allows packaging an application and all relevant frameworks into a portable executable file. The latest version of VMWare Workstation includes a personal use only license. Problem with ThinApp that it is typically licensed per machine, and although if you have appropriate licensing ThinApp’ing .NET + PowerShell is in my opinion the best way to go with WinPE. In any case by creating a ThinApp package of .NET + PowerShell we can get in a really simple format the information we need to make the framework run in PE.
As .NET 3.5 + PowerShell is part of Windows 7, and even removing the feature seemed to leave much of it behind, it was not going to be a suitable OS to do a capture. So to start I went back to my arch nemesis Windows XP. The process was basically this:
1) VMWare’s Workstation automated install on a Windows XP SP3 retail CD.
2) Installed ThinApp into the VM
3) Launched ThinApp Setup Capture
4) Performed a “Prescan” of the System
5) Installed .NET 2.0 SP1 (NetFx20SP1_x86.exe)
6) Installed PowerShell 2.0 (WindowsXP-KB968930-x86-ENG.exe)
7) In ThinApp Setup Capture performed a Postscan and Build. I now have an output folder with all the reg keys + all the files that have changed since the prescan phase. In addition I have a “bin” folder which contains the portable .EXEs that I can take & run anywhere ThinApp is licensed
The reg keys are exported in a format like this:
So using this information I have built a batch file to collect all the required .NET registry keys and files. Probably there are many more reg keys then really required, I can’t be bothered to go and eliminate unnecessary ones. If you have any suggestion let me know.
Running this batch file in Windows 7 will result in a file collection about 740 MB in size. On a clean Windows XP SP3 with .NET 2.0 SP1 + PowerShell 2.0 it will be about 200 MB in size. Both the XP and Windows 7 version will run in Windows PE 3.0 fine. (I haven’t tested earlier versions of PE)
The batch file below can be downloaded here:
Running this batchfile on a machine with .NET and PowerShell installed will generate a folder “Installer” in the directory the batch file is stored. Beneath that two directories will be created Files and Reg.
To install .NET in PE this is what you must do
1) Copy entire contents of Installer\Files folder into root of your BOOT.WIM (X:\)
2) Open the NET_FRAMEWORK.reg file in Installer\REG folder using a text editor and search replace C: to X:
3) Import NET_FRAMEWORK.reg after WinPE has booted. (Some reg keys here may cause a BSOD if you import it into your WinPE hives directly.)
Note: I’ve only tested this on x86 WinPE, may need some modification to work on x64 WinPE. Some potential issues to keep in mind for WinPE x64:
- .NET on x64 system typicall includes a 64-bit + 32-bit Framework (i.e. 64 bit in C:\Windows\Microsoft.NET\Framework64 and C:\Winodws\Microsoft.NET\Framework for 32-bit. If you only want 64-bit remote the Framework folder, and ensure relevant registry keys are all pointing to C:\Windows\Microsoft.NET\Framework64. Your .NET apps should be complied to either Any or x64
- .NET executables can be compiled to force using 32-bit Framework, for these to work you need to include the 32-bit subsystem in x64 WinPE + 32-bit .NET Framework (there is no supported way to do this, but if you want to know how to do it let me know)