How to Create a Self-Extracting Installer using 7Zip for Complex Applications for use with Windows Configuration Designer
A challenge that may arise when trying to use modern deployment techniques with Windows 10 is the need to deploy applications that have complex installation methods. These methods may use setup.exe's that call .msi files or have multiple files or folders. When creating a provisioning package with Windows Configuration Designer (WCD) to join a device to Azure AD you can specify applications to install during the provisioning wizard, however these applications must be a single file. These could also be .bat, .cmd, etc. files, but again, can only be a single file.
7-Zip is a free, open source application that allows for creating self-extracting installers in an .exe format. It allows for repackaging without having to install the application on a reference machine and capture the differences into a MSI file like most repackaging solutions. These self-extracting .exe files can be deployed during the provisioning of a device.
Preparing to Repackage your Application
In this example, we'll be repackaging Office 365 ProPlus Click To Run (CTR) since it has a small footprint consisting of a single setup.exe and configuration.xml which allows for silent installation. Know that this isn't the most efficient way of installing Office 365 ProPlus CTR using provisioning since using the standard Office 365 ProPlus CTR bits will reach out to the internet to download ~1GB+ of files.
Note: If you're looking for a more efficient way to include Office 365 ProPlus CTR into your provisioning package, use the Office Install Toolkit, which will give you the ability to customize your office install and download the bulk of the installation files to reduce the amount of bandwidth your devices will use during provisioning.
- Copy your application to some folder on your machine. For example C:\temp\Office 365 ProPlus
- In this folder, create a new folder called custom
- Download 7-zip from http://www.7-zip.org/ and select the appropriate architecture type for your machine (x86 or x64)
- Install 7zip
- Download the LZMA SDK - http://www.7-zip.org/a/lzma1604.7z
- Right Click the lzma1604.7z, select 7-zip -> Extract Files
- In the Extract to: field, select a location to extract to such as C:\temp\. When it's finished extracting, you should have a folder called C:\temp\lzma1604
- If you are interested in how LZMA compresses the files into a self-extracting zip, you can reference the "C:\temp\lzma1604\DOC\installer.txt"
Repackaging the application
Now that 7Zip and LZMA are both installed, we need to repackage the application. In order to repackage, we need to do four things:
- Zip our source files
- Copy the 7zSD.sfx file from LZMA – this is what creates the self-extracting exe
- Create a config.txt file that includes the installation command and the silent switches
- Run a copy command to take the compressed zip file, the sfx file, and the config file and create a single self-extracting .exe
Let's repackage Office 365
- Open File Explorer and go to C:\Temp\Office 365 ProPlus
- Select the setup.exe and configuration.xml files and select 7Zip -> Add to "Office 365 ProPlus.7z"
You should have an Office 365 ProPlus.7z file in the C:\temp\Office 365 ProPlus folder - In file explorer, copy
"C:\temp\lzma1604\bin\7zSD.sfx" to C:\Temp\Office 365 ProPlus - In file explorer, in the c:\temp\Office 365 ProPlus folder, right click in the white are and select New – Text Document and name the file config.txt
- Open the config.txt file
The content of the config.txt file needs to be in a certain format. The below example is for Office 365, but for your installer you'll need to get the execute file (this could be a setup.exe, or even a .cmd file or some other extension) and whatever the parameters are.
Copy and paste the below example into your config.txt file
;!@Install@!UTF-8! Title="Office 365 PP" BeginPrompt="Do you want to install Office 365 PP?" ExecuteFile="setup.exe" ExecuteParameters="/configure configuration.xml" ;!@InstallEnd@!
If you have a MSI file as the installer, but still have multiple files and/or folders that comprise the installation, you can use the following:
;!@Install@!UTF-8! Title="Title of Application" BeginPrompt="Do you want to install Application?" ExecuteFile="msiexec.exe" ExecuteParameters="/i NameOfMSI.msi /qn /norestart" ;!@InstallEnd@!
Note: Your MSI may have additional properties. Check with the vendor to determine any additional execute parameters that are needed.
- Open a command prompt by clicking the start menu and typing cmd and hitting enter
- Change directory to c:\temp\Office 365 ProPlus by typing cd c:\temp\Office 365 ProPlus
- Create the self-extracting exe by typing:
copy /b 7zSD.sfx + config.txt + "Office 365 ProPlus.7z" O365PPInstaller.exeYou should end up with a temp folder that looks like the following: - Congratulations, you now have a self-extracting exe that can be installed silently.
Testing the EXE
It's recommended to test the exe prior to implementing in a provisioning package to validate that the exe installs successfully. There are two ways to do this:
- Copy the exe to a test machine (A VM is preferred) and run it via cmd prompt using O365PPInstaller.exe -y
- Copy the exe to a test machine (A VM is preferred) and install the exe in the system context
Option 1 is easy, however option 2 is a better test since the provisioning process uses the system context. Use option 1 first just to validate that the exe works. But use option two to make sure it works in the system context. If both tests work, then there's a high likelihood it will work in the provisioning package.
Testing with option 1
- Copy the O365PPInstaller.exe file from C:\temp\Office 365 ProPlus and copy it somewhere on your test machine. In this example, we'll use c:\temp
- Open an admin command prompt on the test machine by going to the start menu, typing in cmd, and pressing ctrl+Shift+Enter at the same time on the keyboard (alternatively, you can right-click on cmd and select Run as Administrator)
- Change directory to c:\temp by typing in cd c:\temp and hitting enter
- Run O365PPInstaller.exe -y
If your configuration file for O365 was configured correctly, O365 ProPlus should install silently (a black window might pop up, but no user intervention is required).
(Optional) Testing with option 2
Testing with option 2 requires the use of psexec to create a command prompt in the system context. This will allow for validation of the application as system, which is the context Intune and the provisioning process will use to install the application.
- Copy the O365PPInstaller.exe file from C:\temp\Office 365 ProPlus and copy it somewhere on your test machine. In this example, we'll use c:\temp
- Download psexec from https://live.sysinternals.com/psexec.exe
(Note: Sysinternals tools are Microsoft tools, psexec.exe is a safe download) - Save the file to c:\temp\psexec.exe
- Open an admin command prompt on the test machine by going to the start menu, typing in cmd, and pressing ctrl+Shift+Enter at the same time on the keyboard (alternatively, you can right-click on cmd and select Run as Administrator)
- Type in c:\temp\psexec.exe -sid cmd -accepteula and hit enter
- A new cmd prompt will open up in the system context. Verify you are running as system by typing whoami and hitting enter
- Change directory to c:\temp by typing in cd c:\temp and hitting enter
- Run O365PPInstaller.exe -y
If your configuration file for O365 was configured correctly, O365 ProPlus should install silently (a black window might pop up, but no user intervention is required).
Integrating with a Provisioning Package
You can create provisioning packages (PPKG) with the Windows Configuration Designer (WCD) tool. This process will show how to download WCD and create a PPKG to provision a device.
- Download Windows Configuration Designer (WCD) from the Windows Store
- Go to the start menu and type store and hit enter
- In the search box type Windows Configuration Designer and hit enter
- Click the Install button
- When the app finishes installing, click Launch from the Windows Store application (alternatively you can find the app in your start menu)
- In Windows Configuration Designer, select Provision desktop devices
- In the New Project wizard, give your package a name and click Finish
- In the Set up device page, type in a name for the device such as Contoso-%RAND:5%
- Click Next
- In the Set up network page, enter your network SSID. If you are going to use a VM or a device without a wireless adapter, make sure to select Off for Connect devices to a Wi-Fi network and click Next
- In the Account Management page, select Enroll in Azure AD and select Get Bulk Token
- In the wizard that pops up, enter the Azure AD account that has rights to enroll devices (this would be a global administrator account, or an account that you have specified in Azure AD) and click Next
- Enter your password and click Sign In
If you get an error, try again. Trying multiple times seems to help. - Click Next once the bulk token has been fetched successfully
- In the Add applications page, click the + sign for Add an Application
- For Application Name, type in Office 365 Pro Plus
- Click Browse for the Installer path
- Select c:\temp\O365PPInstaller.exe
- For command line arguments enter cmd /c "o365ppinstaller.exe" -y
- Click Add
- Click Next
- In the Add certificates page, click Next
- In the Finish page, click Create
- After clicking Create, a link to the package will be listed in the app. The path to the PPKG will be similar to: C:\Users\<YourUserProfile>\Documents\Windows Imaging and Configuration Designer (WICD)\<Name You Gave The Package>The package will be in a folder that looks like the following. All you want is the .ppkg file out of this folder. Take the .ppkg file and copy this to a USB stick.
Provision a New Device
- Image a machine with stock Windows 10 1703 (aka Creators Update) installation media and let it sit at the first screen of the out of box experience (the screen that says "Let's start with region. Is this right?")
- Insert the USB stick that has the provisioning package (the file with the .ppkg extension)You should see a screen that looks like the following:
- The PC will reboot and will be on the Installing provisioning packages… screen for a little while depending on the size or the application. With Office 365 ProPlus, the installer that we captured will reach out to the internet to download the latest bits of Office 365. This can be about 1GB+ of data.
Once the installation is complete, you should be at the lock screen. Dismiss the lock screen and login with an Azure Active Directory Account. If everything succeeded, you should see Office 365 ProPlus installed on the device.
5 Responses
I'm a sysadmin for a SMB who is getting ready for the deployment of Windows 10 in the business. I've been doing a lot of reading about WCD and am excited at the possibility of getting away from Sysprep and imaging. I've created a provisioning file with 4 applications, 2 are msi, and 2 exe (MS Office 2010 and Shoretel Communicator). The MSI files provision properly but the exe packages using your method here do not. I have used both options above for testing and they install just fine. I have tried several times and rechecked everything but can't figure out why they won't install. Can you think of anything else I could try?
Office 2010 is old :) I'd suggest using Office 2016 if possible.
For the command line of the 2 exes, are you using cmd /c setup.exe (or whatever the name of the exe is)? Cmd /c is required in order for the command to exit correctly.
You also may want to try testing your application as system. You can do this by using psexec from sysinternals. You can download psexec from live.sysinternals.com , select psexec and once downloaded, use psexec -sid cmd to open a cmd prompt as system. From there, try to run your installer and see if it installs successfully.
You can also move the app to a different place in the install list. If your exes are 3rd and 4th, move them to 1st and 2nd and see if that works.
Thanks for the response Richard. I have made some progress on this....
I had turned on 'CleanPCWithoutRetainingUserData' to remove some OEM installed software. I took that option out and now the installs work if I double click the .ppkg file from within Windows.
Yes, I have the command right and have tested with psexec. I hadn't tried changing the order though, I'll keep that in mind as I test further.
And yes, I know Office 2010 is old but it works, is expensive to replace and isn't EOL until 2020. Right now we're focused more on getting to Windows 10 before 7 hits EOL.
Thanks again for your work on this.
Hi Richard,
Fantastic article! But I'm also having problems with the 'CleanPCWithoutRetainingUserData' option.
Specifically I get an error from 7-Zip that states "Can't load config info".
I don't have these issues when not using Clean PC.
Did you ever discovery a remedy for this?
Thanks for your help
No, can't say I've used CleanPC recently. Up until 1903 there were some problems with CleanPC and provisioning that caused some issues. In 1903 those issues should be resolved.