用于检查Windows激活状态的批处理文件

问题描述 投票:1回答:2

我希望能够编写Windows激活检查脚本。我的代码在下面,第一行是我希望得到一些帮助的地方,其余的主要是对我要实现的目标的理解。

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

第一行永远不会以我的方式工作,我知道不确定如何检查激活状态,再次感谢所有帮助和建议。谢谢

batch-file
2个回答
1
投票
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
)

但是slmgr的输出已完全本地化。它将仅在英语语言环境中工作。


0
投票

由于某些原因,MC ND脚本在运行if / i行之前已退出

所以我改为这样做:

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
)
© www.soinside.com 2019 - 2024. All rights reserved.