Due to the complexity of Microsoft licensing, App Layering utilizes our own set of scripts to ensure Windows & Office activation. These scripts are a part of the "Citrix App Layering OS Machine Tools," and their misconfiguration is the leading cause of the "Image Preparation OS Rearm Failed" error in App Layering environments.
This document covers the general approach to successfully activating Windows & Office in most App Layering 4.x environments. Specifically, this article is designed for environments that utilize KMS Licensing and non-generalized images (most provisioning methods, including MCS & PVS, require non-generalized images).
If you have a more complex environment, or the issue persists after following this document, please refer to the Office Recipe, which is a 14 page documented covering the scripts in detail:
Office Recipe: "How to Setup Office with App Layering" - https://support.citrix.com/article/CTX224566
Please note - Misconfigured activation scripts are not the only cause of the "Image Preparation OS Rearm Failed" error, and some alternate solutions are provided at the end of this article.
3. When you run "citrix_app_layering_os_machine_tools_4.6.0.exe" kmssetup.cmd is configured as a startup script. You can verify that this local GPO is set correctly by running gpedit.msc, Local Computer Policy, Computer Configuration, Windows Settings, Scripts, Startup to verify it's in the list. Or by by checking this registry key: HKLM\Software\Microsoft\Windows\CurrentVersion\Group Policy\State\Machine\Scripts\Startup\0 - there should be one entry for kmssetup.cmd. If there is no entry, the easiest ways to set it is by re-extracting the scripts on this machine (step a), or by running C:\Windows\Setup\Scripts\kmsdir\gposetup.cmd. If there are two or more entries (sometimes caused by extracting the machine tools multiple times), delete the extra registry keys to run the script until there is only one remaining. Note: In Unidesk 2.x, 3.x, and generalized images, this GPO could also be configured via unattend.exe.
4.Optional step: For increased performance later, you can compile .net assemblies now rather than at run time. In an elevated command line type
5. Now, in C:\Windows\Setup\Scripts, run "SetKMSVersion.exe" as an administrator (this is one of the files extracted by the OS Machine Tools) and click 'Save Script.' Verify that this creates the "runipkato.cmd" file located in C:\Windows\Setup\scripts\kmsdir. This captures your OS version, and is necessary for license activation. If you do not rnu it as an administrator, you will run into issues, as the file will be saved on your desktop rather than where we want it (C:\Windows\Setup\Scripts\Kmsdir)
6. Reboot the machine for good measure, "Shutdown for Finalize" from the desktop, and "Finalize" the layer in the Management Console.
7. Now, install Office on a brand new application layer.
Note: Microsoft licensing is very interconnected! We recommend putting all Office components on the same Application layer. Please refer to the "Layering Strategy" section in document attached to this article for additional information on this topic (https://support.citrix.com/article/CTX224566)
Note: To avoid configuring settings specific to this machine, avoid opening or running any Office applications during packaging.
8. In C:\Windows\Setup\Scripts, run Optimize.hta (or Optimize64.exe in older versions) as an administrator. If you have previously run this, load your settings. You can tell if you have run this before by checking to see if the file "OfficeActivate.txt" exists in C:\Windows\Setup\Scripts\kmsdir. If not, it will be created after you save in step 10.
i. Open cmd.exe as administrator
ii. cd \Windows\Setup\Scripts
iii. Optimize.hta
9. In section 'H' of Optimize.hta (or Optimize64.exe in older versions), check "Activate MS Office via KMS." Only select the product versions you have installed on this layer.
Note: "This scripting will only work if Office is installed in its default location. Additionally, it is not recommended to install more than one version of the same application on the same desktop.
10. Click "Save settings A-J" - This will create flag files. One indicator that you have this step is a file titled "OfficeActivate.txt" in the \kmsdir\ folder, which tells the startup script (kmssetup.cmd) to run "OfficeActivate.cmd"
11. If you are using any OS other than Windows 7 - run "Office2013Windows81_PREP.cmd" as an administrator. You guessed it - It's located in C:\Windows\Setup\Scripts.
Note: Do not let the outdated file name fool you - You must run this for all versions starting with Windows 8.1, and Office 2013 (You must run this for Office 2016, 365, Windows 10, etc)
i. Run cmd.exe as an administrator
ii. cd \Windows\Setup\Scripts
iii. Office2013Windows81_PREP.cmd
12. Next you should run OSPPREAM.exe as an administrator to make sure the layer is properly prepped. This is only necessary if you opened up Office during the packaging/layering process (please do not do this), as it would save machine and user specific settings in the layer - which means all end users would have to "reconfigure" office at first launch. While not usually necessary to run this, we recommend it to be safe.
For Office 2016, the file is located in C:\Program Files\Microsoft Office\Office16
13. Optional step: For later performance improvements, run another ngen update to compile assemblies - In command prompt as an administrator:
i. cd..=====If you are still seeing activation issues or the "Image Preparation OS Rearm Error" in MCS=====
Here are some other settings to check that may also affect Windows & Office Activation, or result in the MCS error