Check the office License Status from batch file

时间秒杀一切 提交于 2019-12-13 08:59:32

问题


I am making a batch file that can check to see if your office 2013 has a icense or not.

for /f "tokens=3 delims=: " %%a in (
'cscript "%ProgramFiles%\Microsoft Office\Office15\OSPP.VBS" /dstatus ^| find "License Status:"' 

) do set "licenseStatus=%%a"
if /i "%licenseStatus%"=="--- LICENSED ---" (
Echo I am Licensed
Pause
EXIT
) Else (
Echo I am NOT Licensed
Pause
EXIT
)

But every time I run this code it all way come back with a I am NOT Licensed. I have check it be running the ospp.vbs script myself it say ---License---. I would like to know where I when wrong with this. Thinking it in the path for this script. I am talking about (%ProgramFiles%\Microsoft Office\Office15\OSPP.VSB /Dstatus) Any help you can give me would like a great help. Thank you for taking the time to read this.


回答1:


You need to use the /I flag with find. Alternatively, you need to search for the string "LICENSE STATUS". Right now, you're doing a case-sensitive search for "License Status," which doesn't appear with that exact capitalization anywhere in the output of OSPP.vbs.

Also, you need to get rid of the spaces in "--- LICENSED ---" because the actual output has no spaces.

@echo off

:: The below directory is for users with a 64-bit operating system
:: 32-bit users can find the script in "%ProgramFiles%"\Microsoft Office\Office15\OSPP.vbs"
for /f "tokens=3 delims= " %%a in ('cscript "%ProgramFiles(x86)%\Microsoft Office\Office15\OSPP.VBS" /dstatus ^| find /i "License Status:"') do (
    set "licenseStatus=%%a"
)

if /i "%licenseStatus%"=="---LICENSED---" (
    Echo I am Licensed
) Else (
    Echo I am NOT Licensed
)

pause


来源:https://stackoverflow.com/questions/32021545/check-the-office-license-status-from-batch-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!