快速命令或批处理脚本来确定 Windows 和 Office 版本

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18820434/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 10:52:54  来源:igfitidea点击:

quick command or batch script to determine Windows and Office version

windowsbatch-filems-office

提问by Reece

I need to do a software audit of more than 300 computers that are neither on the same network, or owned by the same company.

我需要对 300 多台既不在同一网络上又不属于同一家公司的计算机进行软件审计。

Is there an command or small program (that can be run without installing) that I can email to the end-users to run that will output the MS Windows and MS Office versions?

是否有我可以通过电子邮件发送给最终用户运行的命令或小程序(无需安装即可运行),以运行将输出 MS Windows 和 MS Office 版本?

回答by r3ap3r

One possible way of obtaining the current Windows Version and Microsoft Office version is to query the system registry entries using command line.

获取当前 Windows 版本和 Microsoft Office 版本的一种可能方法是使用命令行查询系统注册表项。

To get the windows version using System registry , use the following command:

要使用 System registry 获取 windows 版本,请使用以下命令:

reg query "HKLM\Software\Microsoft\Windows NT\CurrentVersion" /v "ProductName"

This will give an output which can be parsedto get the current windows version/name.

这将给出一个输出,可以对其进行解析以获取当前的 Windows 版本/名称。

To get the current office version , use:

要获取当前的办公版本,请使用:

reg query "HKEY_CLASSES_ROOT\Word.Application\CurVer"

The output of this command gives the office version in number format such as 14, 15, etc.

此命令的输出以数字格式(例如 14、15 等)提供办公版本。

Parse the output to get the version number and matchagainst the list of existing Microsoft office versions to get the name of the version installed:

解析输出以获取版本号并现有 Microsoft Office 版本列表匹配以获取已安装版本的名称:

Office 97   -  7.0
Office 98   -  8.0
Office 2000 -  9.0
Office XP   - 10.0
Office 2003 - 11.0
Office 2007 - 12.0
Office 2010 - 14.0 
Office 2013 - 15.0
Office 2016 - 16.0

Hope this helps!!

希望这可以帮助!!

回答by npocmaka

@echo off
setlocal enableDelayedExpansion
for /f "tokens=2 delims==" %%O in ('ftype ^|findstr /r /I "\OFFICE[0-9]*" 2^>nul') do (
    set "verp=%%~O"
    goto :end_for
)
:end_for

for %%P in (%verp%) do (
    set "off_path=%%~dpP"
    for %%V in ("!off_path:~0,-1!") do (

     set "office_version=%%~nV"
     goto :end_for2
    )
)
:end_for2
echo %office_version%
endlocal

does NOT require administrator permissions and works on Windows XP and above

不需要管理员权限,适用于 Windows XP 及更高版本

回答by Helper

I use this to grab version 2003, 2007, 2010 and 2013.

我用它来抓取 2003、2007、2010 和 2013 版本。

@echo off
setlocal enabledelayedexpansion

for /f "tokens=3 delims=." %%a in ('reg query "HKEY_CLASSES_ROOT\Word.Application\CurVer"') do set reg=%%a

set /a i=0
for %%b in (11 12 14 15) do (
  if %%b == %reg% goto setver
  set /a i+=1
)

:setver
set /a n=0
for %%c in (2003 2007 2010 2013) do (
  if !n! == !i! set ver=%%c && goto endloop
  set /a n+=1
)

:endloop
echo Microsoft Version: %ver%
echo.
endlocal

:end
pause

回答by Matt Williamson

And 1 more using npocmaka's code but adding in a map to make it more user friendly:

还有 1 个使用 npocmaka 的代码但添加了地图以使其更加用户友好:

@echo off
setlocal

call :GetOfficeVer
endlocal
exit /b

:GetOfficeVer
::@echo off
setlocal enableDelayedExpansion
for /f "tokens=2 delims==" %%O in (
    'ftype ^|findstr /r /I "\OFFICE[0-9]*" 2^>nul') do (
        set "verp=%%~O"
        goto :end_for
)
:end_for

for %%P in (%verp%) do (
        set "off_path=%%~dpP"
        for %%V in ("!off_path:~-3,2!") do (
            set "off_ver=%%~nV"
            call :Map !off_ver! && exit /b
        )
)
:Map
set "v=%1"
set "map=11-2003;12-2007;14-2010;15-2013"
call set v=%%map:*%v%-=%%
set v=%v:;=&rem.%
echo Microsoft Office Version: %v%
endlocal
exit /b

回答by Alex Metcalfe

To get the office version under Windows 10, this is quite elegant:

拿到windows 10下的office版本,这个还是挺优雅的:

for /F "tokens=3 delims=." %%O in ('reg query HKEY_CLASSES_ROOT\Word.Application\CurVer') do set _officeVer=%%O

Does not require admin rights and works also on xp and above

不需要管理员权限,也适用于 xp 及更高版本