How MAS Handles Windows Edition Changes and Upgrades: Complete Technical Guide
Microsoft Activation Scripts (MAS) automates Windows edition upgrades by detecting the current edition, resolving the correct generic product key via pkeyhelper.dll, and selecting between three installation methods—slmgr, DISM-API, or CBS XML—depending on the Windows build number.
MAS provides a single-click solution to upgrade Windows editions (e.g., Home to Pro) without losing activation status. The implementation in Change_Windows_Edition.cmd orchestrates native Windows components through pure batch and PowerShell, eliminating the need for external binaries. This article breaks down exactly how MAS detects editions, resolves keys, and executes the upgrade path according to the massgravel/Microsoft-Activation-Scripts source code.
Environment Initialization and Elevation
Before attempting any edition change, MAS normalizes the execution environment. The script forces 64-bit execution on ARM/ARM64 systems and ensures administrative privileges through self-elevation.
In MAS/Separate-Files-Version/Change_Windows_Edition.cmd (lines 31-55), the batch file checks for admin rights and re-launches itself with elevated privileges if necessary:
if not defined _elev (
%psc% "Start-Process -FilePath '%~f0' -ArgumentList '-el' -Verb RunAs"
exit /b
)
The script also sets critical environment variables including %winbuild% to determine which upgrade methods are available for the specific Windows version.
Detecting the Current Windows Edition
MAS implements a cascading detection strategy to identify the installed Windows edition. The primary method uses DISM (/Get-CurrentEdition), falling back to WMI and PowerShell if DISM fails.
According to lines 33-45 in Change_Windows_Edition.cmd, the detection logic executes:
for /f "tokens=3 delims=: " %%a in ('
DISM /English /Online /Get-CurrentEdition ^| find "Current Edition :"
') do set "osedition=%%a"
if not defined osedition (
wmic path SoftwareLicensingProduct where "ApplicationID='55c92734-d682-4d71-983e-d6ec3f16059f'" get LicenseFamily /value 2^>nul
)
If WMI returns no results, MAS falls back to a PowerShell query against the SoftwareLicensingProduct class to extract the LicenseFamily property.
Enumerating Target Editions
Once the current edition is known, MAS must determine which editions are available for upgrade. The approach varies by Windows build number.
For builds 10240 and newer, MAS uses the native DISM command:
DISM /English /Online /Get-TargetEditions | find "Target Edition :" > "%temp%\targets.txt"
For older builds, the script executes an embedded PowerShell routine (the :cbsxml block) that reads the Component Based Servicing (CBS) package database directly to enumerate possible targets. This logic appears at lines 70-74 in Change_Windows_Edition.cmd.
Resolving the Product Key
Before applying the edition change, MAS must obtain the correct generic product key for the target edition. The script implements a two-tier lookup system defined in functions :ced_targetSKU and :ced_windowskey.
Step 1: SKU ID Resolution (lines 46-60)
The script calls pkeyhelper.dll to convert the human-readable edition name (e.g., "Professional") to a numeric SKU ID:
:ced_targetSKU
rem Queries pkeyhelper.dll to map edition name to SKU ID
set "targetSKU=[result from dll call]"
exit /b
Step 2: Key Retrieval (lines 34-42)
Using the SKU ID, MAS first checks an internal hard-coded table (:changeeditiondata, lines 78-135) containing known edition-to-key mappings. If the key is not found in the table, it queries pkeyhelper.dll again via ced_windowskey to extract the matching generic key for the current Windows branch (Retail, OEM, or Volume).
The Three Upgrade Methods
MAS selects between three distinct upgrade paths based on the Windows build number and whether the product key can be installed directly.
Method 1: slmgr /ipk (Simple Key Installation)
For most modern Windows builds, MAS attempts the straightforward approach using Software Licensing Manager. At lines 250-267 in Change_Windows_Edition.cmd:
%psc% "slmgr /ipk %key%"
if %errorlevel%==0 (
echo Key installed successfully. Reboot required.
)
If the key installation succeeds, the edition change is queued and only requires a system restart to complete.
Method 2: DISM-API for Legacy Builds
On builds older than 17134 where a product key alone is insufficient, MAS invokes the DISM-API through a hidden PowerShell block (:dismapi, lines 40-66). This method loads DismApi.dll and calls the internal _DismSetEdition function:
$Dism = Add-Type -Path "$env:SystemRoot\System32\DismApi.dll"
$Dism::DismInitialize()
# ... session creation ...
$Dism::DismSetEdition($Session, $TargetEdition)
This approach forcibly modifies the edition without relying on standard activation channels and automatically triggers a reboot upon success (lines 62-63).
Method 3: CBS XML Staging for Modern Builds
For builds 10240 and newer that support "stage current" operations but require more than a simple key change, MAS generates an unattend XML file via the :cbsxml block (lines 12-36). The script constructs a CBS package instruction set and applies it using:
DISM /English /Online /Apply-Unattend /UnattendFile:"%temp%\cbs.xml"
This method stages the edition components without immediately committing them, allowing the system to finalize the change during the next boot cycle.
Execution Flow and Reboot Handling
The decision logic at lines 185-215 in Change_Windows_Edition.cmd determines which of the three methods to execute:
- Attempt
slmgr /ipkfor direct key installation - Fall back to DISM-API if the key fails on pre-17134 builds
- Use CBS XML for staging on newer builds where DISM-API is unavailable or insufficient
After a successful key installation, MAS informs the user that a manual reboot is required (lines 317-329). However, when using the DISM-API method, the script forces an immediate system restart to complete the edition change.
All operations log detailed output to a ChangeEdition_Logs folder on the desktop for troubleshooting activation or upgrade failures.
Summary
- Environment Setup: MAS forces admin elevation and 64-bit execution normalization before attempting any changes.
- Edition Detection: Uses a cascading fallback from DISM to WMI to PowerShell to identify the current Windows edition.
- Key Resolution: Implements a two-tier lookup using
pkeyhelper.dlland an internal data table (changeeditiondata) to find the correct generic key. - Upgrade Paths: Selects between
slmgr /ipk(modern builds), DISM-API (legacy builds <17134), or CBS XML staging (builds ≥10240). - Logging: All operations write to
%userprofile%\Desktop\ChangeEdition_Logsfor diagnostic purposes.
Frequently Asked Questions
Can MAS upgrade from Windows Home to Enterprise?
Yes, provided the target edition is listed in DISM /Get-TargetEditions. MAS resolves the appropriate Enterprise generic key via pkeyhelper.dll and attempts installation. If the simple key method fails, it automatically falls back to the CBS XML or DISM-API method depending on your build number.
Why does MAS require administrator privileges to change editions?
Windows edition modification requires writing to the Component Based Servicing store and modifying the Software Licensing Service database. The script checks for elevation at lines 31-55 in Change_Windows_Edition.cmd and automatically re-launches itself with admin rights using PowerShell's Start-Process -Verb RunAs if insufficient privileges are detected.
What happens if the product key installation fails?
If slmgr /ipk returns an error, MAS evaluates the Windows build number. On builds older than 17134, it invokes the :dismapi PowerShell block to call _DismSetEdition directly. On newer builds, it generates a CBS unattend XML and executes DISM /Apply-Unattend. Both alternative methods bypass standard Software Licensing Manager limitations that might block the edition change.
Does changing the edition with MAS affect my existing activation?
No. MAS uses generic volume license keys (GVLKs) or retail generic keys that facilitate the edition change without altering the underlying digital entitlement or activation status. After the reboot, Windows maintains its previous activated state under the new edition, provided the hardware signature remains unchanged and the edition supports the existing license type.
Have a question about this repo?
These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:
curl -s "https://instagit.com/install.md" Maintain an open-source project? Get it listed too →