[SOLVED] batch to check for mutiple conditions of Office?

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Dos_Probie
Posts: 233
Joined: 21 Nov 2010 08:07
Location: At My Computer

[SOLVED] batch to check for mutiple conditions of Office?

#1 Post by Dos_Probie » 16 Feb 2014 18:52

I know the if/else statement will only check one condition which works fine if running a 32-bit OS (because it only has the Program Files directory) but when checking on a 64-bit OS that contains both Program Files and Program Files (x86) I cannot get the output I need.
Update [SOLVED]: See code snippet
After poking around in the registry I discovered that Office adds a bitness value of either x64 or x86 so then
it was just a simple matter of adding a reg query script for a 64-bit OS. Maybe this may be useful for someone else.
Now life is good again!..DP :P

Code: Select all

@echo off
:: Office_2010-2013.cmd for Windows 7 x64 or x86

:: ### OSBitCheck
if exist "%systemroot%\syswow64\cmd.exe" (call :OSx64) else (call :OSx86)

:: SECTION FOR 32-BIT OS
:OSx86
:: ### Checking for Office Version on 32-bit OS
if exist "%programfiles%\Microsoft Office\Office14\winword.exe" (call :2010) else (call :2013)
:2013
echo Running Office 2013 32-bit with a 32-bit OS.. && timeout /t 5 >nul
::< code >
exit
:2010
echo Running Office 2010 32-bit with a 32-bit OS.. && timeout /t 5 >nul
::< code >
exit

:: SECTION FOR 64-BIT OS
:OSx64
:: ### Query Registry For Installed Office Bit/Version
reg query "HKLM\SOFTWARE\Microsoft\Office\14.0\Outlook" /v Bitness | findstr x64>nul
if '%errorlevel%' EQU '0' goto:Off64_10
cls
reg query "HKLM\SOFTWARE\Microsoft\Office\15.0\Outlook" /v Bitness | findstr x64>nul
if '%errorlevel%' EQU '0' goto:Off64_13
cls
reg query "HKLM\SOFTWARE\Microsoft\Office\14.0\Outlook" /v Bitness | findstr x86>nul
if '%errorlevel%' EQU '0' goto:Off32_10
cls
reg query "HKLM\SOFTWARE\Microsoft\Office\15.0\Outlook" /v Bitness | findstr x86>nul
if '%errorlevel%' EQU '0' goto:Off32_13
cls

Compo
Posts: 507
Joined: 21 Mar 2014 08:50

Re: [SOLVED] batch to check for mutiple conditions of Office

#2 Post by Compo » 22 Mar 2014 09:24

Here's a similar script which checks for the Office Product using the registry uninstall key.

Code: Select all

@Echo off&SetLocal
Set "KEY="&Set "GUID="&Set "IOV="&Set "MWB=32"&Set "MOB=32"
Echo=%PROCESSOR_ARCHITECTURE% %PROCESSOR_ARCHITEW6432%|Find "64">Nul&&(
   Set "KEY=\Wow6432Node"&Set "MWB=64")
Set "KEY=HKLM\Software%KEY%\Microsoft\Windows\CurrentVersion\Uninstall"
For /f "Delims=" %%a In ('Reg Query %KEY% /k /f "*-001B-*0FF1CE}"') Do (
   If Not Defined GUID Set "GUID=%%~nxa")
If Not Defined GUID (Echo=Unable to find Office Product&GoTo :EndIt)
If %GUID:~20,1% Equ 1 Set "MOB=64"
If %GUID:~4,1% Equ 4 (Set IOV=10) Else (If %GUID:~4,1% Equ 2 (Set IOV=07) Else (
      If %GUID:~4,1% Equ 5 (Set IOV=13) Else (Set IOV=??)))
Echo=&Echo= Office 20%IOV% %MOB%-bit Product installed on a %MWB%-bit OS
:EndIt
TimeOut /t 5 1>Nul

Dos_Probie
Posts: 233
Joined: 21 Nov 2010 08:07
Location: At My Computer

Re: [SOLVED] batch to check for mutiple conditions of Office

#3 Post by Dos_Probie » 26 Mar 2014 08:18

Thanks for the info Compo, after posting this I realized that the most reliable way would be via the registry uninstall section
as well and not using bit as versions earlier than 2010 used Guids or not bit at all. btw Welcome to DosTips 8)

Code: Select all

@echo off&&setlocal&&Title, + Office Edition + 

:: Microsoft Office Versions (Displays most popular installed editions for Office - 2000, XP, 2003, 2007, 2010, 2013 and 365)

:Microsoft Office 2000 Professional
(For /f "Tokens=1,2*" %%a In ('reg query "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{00010409-78E1-11D2-B60F-006097C998E7}" /v DisplayName') Do Set Off_Ver=%%c) 2>nul
:Microsoft Office XP Professional with FrontPage
(For /f "Tokens=1,2*" %%a In ('reg query "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{90280409-6000-11D3-8CFE-0050048383C9}" /v DisplayName') Do Set Off_Ver=%%c) 2>nul
:2003 Standard
(For /f "Tokens=1,2*" %%a In ('reg query "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{91120409-6000-11D3-8CFE-0150048383C9}" /v DisplayName') Do Set Off_Ver=%%c) 2>nul
:2003 Business
(For /f "Tokens=1,2*" %%a In ('reg query "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{91CA0409-6000-11D3-8CFE-0150048383C9}" /v DisplayName') Do Set Off_Ver=%%c) 2>nul
:2003 Professional
(For /f "Tokens=1,2*" %%a In ('reg query "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{91110409-6000-11D3-8CFE-0150048383C9}" /v DisplayName') Do Set Off_Ver=%%c) 2>nul
:2007 Standard
(For /f "Tokens=1,2*" %%a In ('reg query "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\STANDARDR" /v DisplayName') Do Set Off_Ver=%%c) 2>nul
:2007 ProPlus
(For /f "Tokens=1,2*" %%a In ('reg query "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\PROPLUS" /v DisplayName') Do Set Off_Ver=%%c) 2>nul
:2010 Standard
(For /f "Tokens=1,2*" %%a In ('reg query "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Office14.SingleImage" /v DisplayName') Do Set Off_Ver=%%c) 2>nul
:2010 ProPlus
(For /f "Tokens=1,2*" %%a In ('reg query "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Office14.PROPLUS" /v DisplayName') Do Set Off_Ver=%%c) 2>nul
:2013 Standard
(For /f "Tokens=1,2*" %%a In ('reg query "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Office15.SingleImage" /v DisplayName') Do Set Off_Ver=%%c) 2>nul
:2013 ProPlus
(For /f "Tokens=1,2*" %%a In ('reg query "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Office15.PROPLUS" /v DisplayName') Do Set Off_Ver=%%c) 2>nul
:2013 365 Home Premium
(For /f "Tokens=1,2*" %%a In ('reg query "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\O365HomePremRetail - en-us" /v DisplayName') Do Set Off_Ver=%%c) 2>nul
echo. %Off_Ver%
echo.
pause

Compo
Posts: 507
Joined: 21 Mar 2014 08:50

Re: [SOLVED] batch to check for mutiple conditions of Office

#4 Post by Compo » 26 Mar 2014 09:16

Just to explain, it simply looks for information specific to Microsoft Word. It is considered as the Main Application in Office and is included in all versions. Additionally I can think of no reason to install any Office package without including it. I know many people however who choose not to install one or more of every other Application

So if you are reading this after suport for Office 2003 has ended, this will pick up on the Operating System architecture and Office architecture for the currently supported and installed Microsoft Office packages, as long as Microsoft Word is an installed component.

Post Reply