'Batch file to check windows activation status

I'd like to be able to script my windows activation checks. My code is below, the first line is the bit I would appreciate some assistance with, the rest is there mainly to give an idea of what I'm trying to achieve.

if slmgr /dli = True (
    do something
    ) else (
        do something else
        )
    )

The first line will never work the way I have it I understand that not sure how to go about checking the activation status, again all help and advice appreciated. Thanks



Solution 1:[1]

For some reason MC ND script exited before it run the if /i line

so I did this instead:

cscript //nologo "%systemroot%\system32\slmgr.vbs" /dli 2>nul | find "License Status:" | find "Licensed" >nul

IF %ERRORLEVEL% == 0 (
    EXIT /b 0
) ELSE (
    EXIT /b 1
)

Solution 2:[2]

You can go with the following code: for /f "tokens=3 delims=: " %%a in ( 'cscript //nologo "%systemroot%\system32\slmgr.vbs" /dli ^| find "License Status:"' ) do set "licenseStatus=%%a"

if /i "%licenseStatus%"=="Licensed" ( do something ) else ( do something

Alternatively, you can visit the link KMSpico for more information.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 DefToneR
Solution 2 Ajay Noorie