quick command or batch script to determine Windows and Office version
Asked Answered
O

8

8

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.

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?

Orchestra answered 16/9, 2013 at 4:29 Comment(2)
I can use 'systeminfo' in the command prompt to output to a CSV but there is no MS Office info in there obviouslyOrchestra
These should be two separate questions.Jacobah
H
18

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

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

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

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

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.

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

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

Henotheism answered 16/9, 2013 at 5:9 Comment(0)
F
2
@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

Fuss answered 16/9, 2013 at 5:17 Comment(0)
J
1

I use this to grab version 2003, 2007, 2010 and 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
Jungly answered 14/7, 2015 at 7:57 Comment(2)
Does anyone have one that works for Office 2019? I cannot get mine to work and thought I would ask before creating another thread.....Corydalis
@Corydalis I believe all versions above Office 16 all have the same "version" number unfortunately. Did you find an answer/start a thread?Jacobah
T
1

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

@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
Telegonus answered 20/8, 2015 at 19:25 Comment(0)
A
1

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

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

Aldenalder answered 22/5, 2018 at 13:1 Comment(1)
I had to change %%0 to %0Medea
J
0

I'm not here for detecting Windows Version, I feel like thats well covered in other answers and should have been a separate question. But, Office is the trick one IMO. Here is how I detect MS Office Version & Arch.

Note: This is barely tested on two x32 bit different installations, but "should" catch them all.

@ECHO OFF
CLS
setlocal enableextensions enabledelayedexpansion
::FreeSoftwareServers.com

set key="*0FF1CE*"
set threesixtyfivekey="O365*"
set keypath=

set arrsize=1
set arg[0]="HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"
set arg[1]="HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall"
for /l %%n in (0,1,%arrsize%) do (
 FOR /F "tokens=* USEBACKQ" %%N IN (`REG QUERY !arg[%%n]! /f %threesixtyfivekey% /k 2^>nul`) DO (
  ECHO "%%N" | FIND /I "HKEY">Nul && (
   If %%n == 0 (
    set arch=x32
   ) ELSE (
     set arch=x64
   )
   set keypath=%%N
   goto keypathFound
  ) 
 )
 FOR /F "tokens=* USEBACKQ" %%N IN (`REG QUERY !arg[%%n]! /f %key% /k 2^>nul`) DO (
  ECHO "%%N" | FIND /I "HKEY">Nul && ( 
   If %%n == 0 (
    set arch=x32
   ) ELSE (
     set arch=x64
   ) 
   set keypath=%%N
   goto keypathFound
  ) 
 )
)
GoTo end

:keypathFound
FOR /F "skip=2 tokens=1,2* USEBACKQ" %%N IN (`reg query "%keypath%" /t REG_SZ  /v "DisplayName"`) DO (
 IF /I "%%N" == "DisplayName" (
  SET OVer=%%P%~1
  GoTo Found
 )
)

:Found
for /f "tokens=1-20 delims=abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!@#$&*()-= " %%a in ("%OVer%") do (
   IF %%a == 64 (
     set ONum=%%b
     GoTo varset
   )
   IF %%a == 32 (
     set ONum=%%b
     GoTo varset
   )
   set ONum=%%a
)

:varset
  Echo Office Number: %ONum%
  ECHO Office Display Name:  %OVer%
  ECHO Software Architecture:  %arch%
  PAUSE
:End
Jacobah answered 2/9, 2021 at 23:8 Comment(0)
I
0

No, this does NOT recognize 64bit Office.

Immaterialism answered 17/8, 2022 at 7:31 Comment(1)
As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.Asyllabic
F
0
@echo off
SetLocal EnableExtensions
SetLocal EnableDelayedExpansion
for /f "delims=" %%a in ('"wmic OS get Caption /value|find "^=""') do set "%%a"
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 16) do (
  if %%b == %reg% goto setver
  set /a i+=1
)

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

:endloop

if exist "%PROGRAMFILES(X86)%" (set winbit=64) else (set winbit=86)
goto %winbit%
:64
if exist "%PROGRAMFILES%\Microsoft Office" (set offbit=64)
if exist "%PROGRAMFILES(X86)%\Microsoft Office" (set offbit=86)
goto result
:86
if exist "%PROGRAMFILES%\Microsoft Office" (set offbit=86)
:result
echo %Caption:~,-1% x%winbit%-bit
echo Microsoft Office %ver% x%offbit%-bit
pause
Forecastle answered 5/5, 2024 at 18:20 Comment(1)
Thank you for contributing to the Stack Overflow community. This may be a correct answer, but it’d be really useful to provide additional explanation of your code so developers can understand your reasoning. This is especially useful for new developers who aren’t as familiar with the syntax or struggling to understand the concepts. Would you kindly edit your answer to include additional details for the benefit of the community?Coup

© 2022 - 2025 — McMap. All rights reserved.