Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
187 views
in Technique[技术] by (71.8m points)

scripting - Check the office License Status from batch file

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 OfficeOffice15OSPP.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 OfficeOffice15OSPP.VSB /Dstatus) Any help you can give me would like a great help. Thank you for taking the time to read this.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.

enter image description here

@echo off

:: The below directory is for users with a 64-bit operating system
:: 32-bit users can find the script in "%ProgramFiles%"Microsoft OfficeOffice15OSPP.vbs"
for /f "tokens=3 delims= " %%a in ('cscript "%ProgramFiles(x86)%Microsoft OfficeOffice15OSPP.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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...