I have been using the code that others have shared and I would like to thank them but I dont know who did it. But I have code that works great and gets me all the Office versions but I cannot get it to do Office 2019.
I am hoping someone knows the extra line to add to make it work....
When I run it on pre 2019, it is fine. But on 2019, it comes back with Desktop.
cls
@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
if [%office_version%] == [] echo No Office installed & goto end
echo %office_version%
:end
endlocal
pause
@
TimeOut /t 5 1>Nul
pause
I'd be interested to know what the following adapted code outputs. It was written for earlier versions of Office, and I have made a guess at what change to make for the newest version.
@Echo Off & Setlocal EnableExtensions DisableDelayedExpansion
If Defined PROCESSOR_ARCHITEW6432 (
Start "" /D "%__CD__%" "%SystemRoot%\SysNative\cmd.exe" /C "%~f0" & Exit /B)
Set /A "OSA=MWB=%PROCESSOR_ARCHITECTURE:~-2%"
If %OSA% Equ 86 Set "MWB=32"
Set "REG=%__AppDir__%reg.exe"
Call :Chk
If Not Defined MOB If %MWB% Equ 64 Call :Chk \Wow6432Node
If Not Defined MOB (Echo Microsoft Office product not installed & GoTo EndIt
) Else If Not Defined IOV (Echo Unable to determine Microsoft Office version
GoTo EndIt)
Echo %MWB%-bit OS with an Office %IOV% %MOB%-bit product installed in %OIL%
:EndIt
Setlocal EnableDelayedExpansion & For /F "Tokens=1,2" %%G In ("!CMDCMDLINE!"
) Do Endlocal & If /I "%%~nG" == "cmd" If /I "%%~H" == "/c" Pause
GoTo :EOF
:Chk
Set "GUID=" & Set "IOV=" & Set "MOB=" & Set "OIL="
Set "Key=HKLM\Software%1\Microsoft\Windows\CurrentVersion\Uninstall"
For /F Delims^= %%G In ('%REG% Query "%Key%" /K /F "*-001B-*0FF1CE}" 2^>NUL'
) Do Set "GUID=%%~nxG" & GoTo Next
:Next
If Not "%GUID:~-1%"=="}" Set "GUID="
If Not Defined GUID Exit /B
Set "MOB=32" & If "%GUID:~20,1%" == "1" Set "MOB=64"
If "%GUID:~4,1%" == "2" Set "IOV= 2007"
If "%GUID:~4,1%" == "4" Set "IOV= 2010"
If "%GUID:~4,1%" == "5" Set "IOV= 2013"
If "%GUID:~4,1%" == "6" Set "IOV= 2016"
If "%GUID:~4,1%" == "7" Set "IOV= 2019"
For /F Tokens^=2* %%G In ('%REG% Query "%Key%\%GUID%" /V "InstallLocation"
2^>NUL') Do Set "OIL=%%H"
If Not Defined OIL Set "OIL=an unknown location"
Exit /B
*Please note, that this was designed to use the data for Microsoft Word, because I decided that everyone who installs Office would always install Word. It should therefore work with Word 2007 onwards, and any Office version from 2007 onwards, (with Word installed as a component).