从批处理文件检查办公室许可证状态 [英] Check the office License Status from batch file

查看:203
本文介绍了从批处理文件检查办公室许可证状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在制作一个批处理文件,可以检查您的Office 2013是否具有许可证.

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
)

但是,每次我运行此代码时,所有代码都会以我未获得许可"的方式返回.我已经检查它自己运行了ospp.vbs脚本,它说--- License ---.我想知道我错在哪里.在此脚本的路径中进行思考.我正在谈论(%ProgramFiles%\ Microsoft Office \ Office15 \ OSPP.VSB/Dstatus)您能给我的任何帮助都将是一个很大的帮助.感谢您抽出时间来阅读.

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.

推荐答案

您需要将/I标志与find一起使用.或者,您需要搜索字符串"LICENSE STATUS".现在,您正在对许可证状态"进行区分大小写的搜索,在OSPP.vbs输出中的任何位置都不会出现确切的大写字母.

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.

此外,由于实际输出中没有空格,因此需要消除"--- LICENSED ---"中的空格.

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

这篇关于从批处理文件检查办公室许可证状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆