Search code examples
batch-filescriptingoffice-2013

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 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.


Solution

  • 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 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