-3

I'm trying to put together a batch file that would select the appropriate bit version of executables when run by the user. I found this code on stackoverflow: Batch file check office architecture version The problem is that it does not work when I paste it into a text file on my desktop and rename it .bat in my virtual machine that has 64-bit Office 2010 installed: it claims it is 32-bit, the default value set in the code. Not being adept in checking registry entries, I'm wondering if there isn't a ready-made version out there somewhere that actually works. I'm also wondering why there isn't a simple way to determine this. I would have thought that this is something that Microsoft would make easily accessible to developers.

RobH
  • 3
  • 2
  • Why do you need to do this? It's not entirely clear what you are trying to accomplish. – Herohtar Jan 12 '20 at 02:30
  • What difference does it make. Typing `winword` will always start it. –  Jan 12 '20 at 04:06
  • And developers usually have no need to know. My 32 bit scripts will work fine on either version of Word and vice versa. –  Jan 12 '20 at 05:03
  • [How-to: Detecting 64 bit vs 32 bit](https://ss64.com/nt/syntax-64bit.html) – aschipfl Jan 13 '20 at 17:37

1 Answers1

1

If you're wanting to check the bitness, version and install location of Microsoft Office, you could give this script a test to see if it works for you any better:

@Echo Off
If Defined PROCESSOR_ARCHITEW6432 (
    Start "" /D "%__CD__%" "%SystemRoot%\SysNative\cmd.exe" /C "%~f0"&Exit /B)
Set /A "OSA=MWB=%PROCESSOR_ARCHITECTURE:~-2%"
If %OSA%==86 Set "MWB=32"
Set "MOB="&Set "GUID="&Set "REG=%__AppDir__%reg.exe"
Call :Chk
If Not Defined MOB If %MWB%==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 20%IOV% %MOB%-bit product installed in %OIL%
:EndIt
>Nul Timeout -1
GoTo :EOF

:Chk
Set "MOB="&Set "GUID="&Set "OIL="
Set "Key=HKLM\Software%1\Microsoft\Windows\CurrentVersion\Uninstall"
For /F Delims^= %%A In ('""%REG%" Query "%Key%" /K /F "*-001B-*0FF1CE}""'
)Do Set "GUID=%%~nxA"&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=07"
If "%GUID:~4,1%"=="4" Set "IOV=10"
If "%GUID:~4,1%"=="5" Set "IOV=13"
If "%GUID:~4,1%"=="6" Set "IOV=16"
If Not Defined IOV Exit /B
For /F Tokens^=2* %%A In ('""%REG%" Query "%Key%\%GUID%" /V "InstallLocation""'
)Do Set "OIL=%%B"
Exit /B

Please note however, that this script was designed to work with Windows Microsoft Office products from versions 2007 up to 2016 inclusive. The script only checks for a specific uninstall key for Microsoft Word, (it is assumed that only in very rare cases would somebody install Office without including the Word product), and there is no guarantee that all versions will use the same uninstall key.

I will not be modifying this code for any additions/changes to your question, or providing help on modifications for purposes other than those for which it was intended.

Compo
  • 36,585
  • 5
  • 27
  • 39
  • Compo's code does work for me. Thanks. I have however found a way to accomplish what I want to do, without using the batch file, so I guess I don't "need" it. But it is good to know. Not sure why I'm accumulating negative votes. Poor first experience for a newbie. – RobH Jan 15 '20 at 01:49
  • So that's what that greyed-out check mark is for! – RobH Jan 16 '20 at 03:43