Skip to main content

How to Get the Windows Activation Status in Batch Script

Verifying if a Windows installation is properly activated is a crucial task for system administrators, PC builders, and refurbishers. An unactivated system may have restricted personalization options, constant watermarks, and limited access to specific Windows features. By using a Batch script to query the Software Licensing service, you can automatically determine if a system is "Licensed," "Notification," or "Initial Grace Period."

This guide explains how to use the slmgr (Software License Manager) and wmic tools to programmatically pull activation data.

Why Check Activation Status?

  • Deployment Verification: Ensuring that a newly imaged machine has successfully contacted the KMS or Microsoft activation servers.
  • Auditing: Creating a report of activation statuses for a fleet of machines to identify license issues.
  • Asset Management: Identifying computers that are running on "Evaluation" or "Grace Period" licenses before they expire.
No Admin Rights for Simple Checks

While many license management tasks require administrator privileges, simply querying the basic activation status (slmgr /xpr) can often be done as a standard user, depending on the system's security policies.

Method 1: Using SLMGR (Visual/Human Friendly)

The Windows Software License Manager (slmgr.vbs) is a VBScript file located in System32. It is the primary way to interact with the licensing engine.

Quick Status Pop-up

@echo off
echo [PROCESS] Checking activation expiration...
:: /xpr shows the expiration date or "Permanently Activated"
cscript //nologo %systemroot%\system32\slmgr.vbs /xpr
pause

Detailed Information

@echo off
echo [PROCESS] Retrieving detailed license info...
:: /dli shows more technical data including license type (OEM, Retail, Volume)
cscript //nologo %systemroot%\system32\slmgr.vbs /dli
pause

Method 2: Using WMIC (Best for Scripts/Logs)

If you need to use the activation status in an IF statement or save it to a silent log file without pop-up windows, wmic is the superior choice.

@echo off
setlocal EnableDelayedExpansion

echo [PROCESS] Querying license status...

:: LicenseStatus 1 means 'Licensed' (Activated)
:: Query the LicenseStatus code from the active Windows license
set "ACTIVATED=0"
for /f "skip=1 tokens=*" %%i in ('wmic path SoftwareLicensingProduct where "PartialProductKey is not null" get LicenseStatus 2^>nul') do (
for /f "tokens=*" %%j in ("%%i") do (
if "%%j"=="1" set "ACTIVATED=1"
)
)

if "!ACTIVATED!"=="1" (
echo [SUCCESS] Windows is ACTIVATED.
) else (
echo [WARNING] Windows is NOT ACTIVATED or is in a Grace Period.
)
pause

Creating a Robust Activation Auditor

The following script combines different methods to provide a comprehensive report on the machine's licensing state.

@echo off
setlocal EnableDelayedExpansion

echo ============================================================
echo Windows Activation Status Auditor
echo ============================================================

:: 1. Get the Activation Status (Numerical)
:: 0 = Unlicensed, 1 = Licensed, 2 = OOBE Grace, 3 = Out-of-Box Grace
set "L_STATUS="
for /f "tokens=2 delims==" %%i in ('wmic path SoftwareLicensingProduct where "PartialProductKey is not null" get LicenseStatus /value 2^>nul ^| find "="') do (
for /f "delims=" %%j in ("%%i") do set "L_STATUS=%%j"
)

:: 2. Convert code to human-readable text
if "!L_STATUS!"=="1" (
set "MSG=Permanently Activated (Licensed)"
) else if "!L_STATUS!"=="2" (
set "MSG=OOBE Grace Period"
) else if "!L_STATUS!"=="3" (
set "MSG=Out-of-Tolerance Grace Period"
) else (
set "MSG=NOT ACTIVATED / Evaluation"
)

:: 3. Output results
echo Date: %date% %time%
echo Computer: %COMPUTERNAME%
echo Status: !MSG!

:: 4. Show Expiration info (For Volume/KMS licenses)
echo.
echo [DETAILS] Expiration Information:
cscript //nologo %systemroot%\system32\slmgr.vbs /xpr

echo ============================================================
pause

Common Pitfalls and How to Avoid Them

Multiple Products in WMI

When querying SoftwareLicensingProduct, Windows returns many items (Office, different Windows components).

Wrong Way:

wmic path SoftwareLicensingProduct get LicenseStatus
:: This will return a list of 20+ numbers, most of which are 0.

Correct Way: Always filter the query using where "PartialProductKey is not null". This ensures you are targeting the actual OS license that has been installed.

Pop-up Windows with SLMGR

If you run slmgr.vbs /xpr without cscript //nologo, Windows will open a graphical message box.

SEO and UX Tip

In a Batch script, always prefix your slmgr calls with cscript //nologo. This forces the output into the command prompt window rather than a pop-up, making it much easier to read and log.

Best Practices for License Management

  1. Check for KMS Connection: If your machine is part of an enterprise, use slmgr /dlv to see the "KMS machine name." This helps identify if the machine can't "see" the license server.
  2. Combine with Edition Check: Always check the activation status alongside the Windows Edition (Home vs Pro) to ensure you have the correct license for the OS version you are running.
  3. Silent Monitoring: Run the auditor script via a scheduled task and have it email you if L_STATUS is anything other than 1.
Digital Licenses

Modern Windows 10/11 machines often use "Digital Licenses" tied to the hardware. These will show as Licensed even if no product key is manually entered by the user.

Conclusion

Getting the Windows activation status via Batch script is a fundamental requirement for professional system deployment and auditing. By utilizing the slmgr utility for detailed reports and wmic for logical scripting integration, you can maintain a clear view of your organization's licensing compliance. This automated approach ensures that you catch activation failures before they affect the end-user experience, providing a reliable way to verify that your Windows environment is fully legitimate and operational.