Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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

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

1 Answer

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...