Enabling and Utilizing Script Debug Mode Output in Microsoft Activation Scripts
Set the _debug variable to any non-zero value in MAS_AIO.cmd or related activator scripts to capture full execution traces to _tmp.log for troubleshooting activation failures.
The Microsoft Activation Scripts (MAS) from the massgravel/Microsoft-Activation-Scripts repository are pure Windows batch files that handle Windows, Office, and ESU activation. Understanding how to enable and utilize script debug mode output allows power users and administrators to diagnose failed activations, verify KMS server communication, and audit command execution. This guide covers the debug implementation found in both the All-In-One and Separate-Files versions of the codebase.
How Debug Mode Works in MAS
The debug system relies on a single variable check that redirects execution flow to a dedicated logging subroutine, capturing every command without altering the activation logic.
The Debug Flag Variable
In MAS/All-In-One-Version-KL/MAS_AIO.cmd at lines 4339-4342, the script initializes a control variable:
:: Debug Mode:
:: To run the script in debug mode, change 0 to any parameter above that you want to run, in below line
set "_debug=0"
When _debug remains 0, the script runs normally. Any other value triggers diagnostic logging.
Conditional Branching Logic
Later in the execution flow, the script evaluates this variable to determine whether to generate a trace:
if "%_debug%" EQU "0" (
goto :_debug
)
This check bypasses the standard completion routine and jumps to the :_debug label, which handles output redirection.
The Debug Subroutine and Log Capture
The :_debug subroutine captures both stdout and stderr to a temporary file. As implemented in MAS/Separate-Files-Version/Activators/Online_KMS_Activation.cmd (lines 45-46):
@call :_debug "%_debug%" >"%~dp0_tmp.log" 2>&1
This redirection ensures every echo, set, if, and external command—including calls to slmgr.vbs or cscript—generates a permanent record in _tmp.log located in the script's directory (%~dp0).
Enabling Debug Mode in Microsoft Activation Scripts
You can activate debug mode through three primary methods depending on whether you need a permanent configuration or a one-time diagnostic run.
Method 1: Editing the Script Directly
Modify the source file to enable logging permanently. Open MAS_AIO.cmd and locate line 4339:
:: Change this:
set "_debug=0"
:: To:
set "_debug=1"
Save the file and execute normally. The script automatically generates _tmp.log upon completion.
Method 2: Environment Variable Override
For temporary debugging without source modification, set the variable in your command prompt session before launching:
set _debug=1
MAS_AIO.cmd
notepad "%~dp0_tmp.log"
This approach overrides the hardcoded default for the current session only, leaving the original script unchanged.
Method 3: Separate Files Version
The modular activators implement identical debug logic. For example, in MAS/Separate-Files-Version/Activators/TSforge_Activation.cmd (lines 53-56), edit the flag:
set "_debug=1"
Then run TSforge_Activation.cmd to generate a diagnostic log specific to that activation method. The same pattern applies to Online_KMS_Activation.cmd and other separate-file activators.
Analyzing Debug Output
The _tmp.log file contains comprehensive execution details essential for troubleshooting:
- Variable states: Values of
_actmethod,_actwin,_actoff, and internal flags showing which activation path was selected - External command traces: Exact command lines sent to
slmgr.vbs,cscript, or WMI for KMS/Online activation - Error streams: Full stderr output from failed system calls or network timeouts
- Registry queries: Results of license status checks and product key applications
Open the log with any text editor to identify execution flow or command failures.
Summary
- The
_debugvariable inMAS_AIO.cmdcontrols diagnostic logging for the entire activation workflow according to the massgravel/Microsoft-Activation-Scripts source code. - Setting
_debugto any non-zero value triggers the:_debugsubroutine, redirecting all output to_tmp.logvia2>&1redirection. - You can enable debugging permanently by editing line 4339 in the All-In-One script or temporarily via environment variables.
- Separate-file activators like
Online_KMS_Activation.cmdandTSforge_Activation.cmduse identical debug implementations at their respective entry points. - The log captures all batch commands, variable states, and external tool outputs without modifying activation behavior.
Frequently Asked Questions
Where is the debug log file saved?
The script writes _tmp.log to the same directory as the executing batch file using the %~dp0 expansion. For MAS_AIO.cmd, this appears in MAS/All-In-One-Version-KL/. Use type _tmp.log or notepad _tmp.log to view the contents immediately after execution.
Can I use debug mode with unattended activation?
Yes. The _debug flag functions identically in both interactive menu mode and unattended parameter mode. Whether you pass activation arguments via command line or select options manually, setting _debug=1 forces the script to generate the execution log before exiting.
Does debug mode change the activation behavior?
No. Debug mode only affects output redirection to _tmp.log; it does not modify the activation logic, KMS server selection, or injection methods. The script executes the same commands but records them to disk, making it safe to use for troubleshooting production systems.
How do I disable debug mode after troubleshooting?
Revert the _debug variable to 0 in the script file, or remove the environment variable from your session. In MAS_AIO.cmd, change set "_debug=1" back to set "_debug=0" at line 4339. Delete the _tmp.log file afterward to clean up diagnostic data.
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 →