0

I have an install.bat file written for me by someone. It needs to install an app based on the bitness of MSOffice on a client terminal. It also needs to run an SQL client driver install file based on the bitness of Windows.

The SQL part works fine. But it constantly installs the 32bit version of the app instead of the 64bit when i definitely have 64bit office installation (have tested on 2 machines both with 64bit office). I'm sure that an expert would be able to glance through the code and quickly tell me what the issue is. This isn't my area of expertise but I know it's not terribly complicated. In the install folder there is a folder called Source32 and Source64. Two 32bit apps in the Source32 and two 64bit apps in the Source64 folder. It fetches these from the relevant folder and puts them into a created folder in root directory (C:\QuickSuite). I only have a very vague idea of what i am looking at so i am not even that sure what to try.

@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 6 (Set IOV=16) 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
If %MWB% == 64 (
@Echo Windows 64-bit...
msiexec /i "%~dp0sql64\sqlncli_x64.msi" IACCEPTSQLNCLILICENSETERMS=YES /qb
)
If %MWB% == 32 (
@Echo Windows 32-bit...
msiexec /i "%~dp0sql32\sqlncli_x86.msi" IACCEPTSQLNCLILICENSETERMS=YES /qb
)
cd %~dp0
SET _source64=.\Source64
SET _source32=.\Source32
SET _dest=%systemdrive%\QuickSuite
SET _FrontOffice=.\FrontOffice
SET _RemoteSMS=.\RemoteSMS
SET _dest_RemoteSMS=%systemdrive%\QuickSuite\RemoteSMS
SET _dest_FrontOffice=%systemdrive%\QuickSuite\FrontOffice

If %MOB% == 64 (
@echo Microsoft Office is 64-bit 
robocopy %_source64% %_dest% /E
robocopy %_FrontOffice% %_dest_FrontOffice% /E
robocopy %_RemoteSMS% %_dest_RemoteSMS% /E
)
If %MOB% == 32 (
@echo Microsoft Office is 32-bit 
robocopy %_source32% %_dest% /E
robocopy %_FrontOffice% %_dest_FrontOffice% /E
robocopy %_RemoteSMS% %_dest_RemoteSMS% /E
)
:EndIt
TimeOut /t 5 1>Nul
  • The script defaults to Win32 and is set to 64 based on the global variables `%PROCESSOR_ARCHITECTURE%` and `%PROCESSOR_ARCHITEW6432%`. It's working as intended on my PC. I suggest checking what that global variable is set to on the computers in question (on the command line input `echo.%processor_architecture% %processor_architeW6432%`). – BDM Apr 23 '19 at 03:29
  • Just to add, the proper way to check if an OS is 32 or 64 bit is detailed [here](https://stackoverflow.com/questions/12322308/batch-file-to-check-64bit-or-32bit-os). – BDM Apr 23 '19 at 03:33
  • Please read the Microsoft article [WOW64 Implementation Details](https://docs.microsoft.com/en-us/windows/desktop/WinProg64/wow64-implementation-details) as well as the other pages linked on this page to understand how Windows on Windows works. `%PROCESSOR_ARCHITECTURE%` expands to `x86` even on 64 bit Windows if the batch file is executed by x86 version of `cmd.exe` in `%SystemRoot%\SysWOW64` (because of calling application is an x86 application). It is better to use `if "%ProgramFiles(x86)" == ""` which is true on 32 bit Windows, but not true on 64 bit Windows even in 32 bit environment. – Mofi Apr 23 '19 at 06:23

1 Answers1

0

Here's a possible example based on your provided code and what I think you're trying to do with it:

@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"

For %%A In (MSIExec Reg RoboCopy)Do Set "%%A=%__AppDir__%%%A.exe"
Echo Windows %MWB%-bit...
"%MSIExec%" /i "%~dp0sql%MWB%\sqlncli_x%OSA%.msi" IACCEPTSQLNCLILICENSETERMS=YES /qb

Call :Chk
If Not Defined MOB If %OSA%==64 Call :Chk \Wow6432Node
If Not Defined MOB (Echo Office Product not installed&GoTo :EndIt)
Echo Microsoft Office %MOB%-bit Product is installed
"%RoboCopy%" "%~dp0Source%MWB%" "%SystemDrive%\QuickSuite" /E
"%RoboCopy%" "%~dp0FrontOffice" "%SystemDrive%\QuickSuite\FrontOffice" /E
"%RoboCopy%" "%~dp0RemoteSMS" "%SystemDrive%\QuickSuite\RemoteSMS" /E

:Endit
Timeout 5 /NoBreak>Nul
GoTo :EOF

:Chk
Set "MOB="&Set "GUID="
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"
Exit /B
Compo
  • 36,585
  • 5
  • 27
  • 39
  • Thank you so much i will try this asap – BlazeEigenmann Apr 24 '19 at 10:08
  • Ok the windows part worked perfectly although i need to try this on another machine because it worked originally on this machine anyway (although yours is neater) but it returned 'Office not installed' for the Office bitness part which is not the case. However i will go through the links you sent me and see if i can fathom this out. Thank you kindly. – BlazeEigenmann Apr 24 '19 at 10:14
  • Could you please tell me the Operating System and post the content of the first registry key output from each of the following searches, `"%__AppDir__%Reg.exe" Query "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall" /K /F "*-001B-*0FF1CE}"` and `"%SystemRoot%\SysWOW64\Reg.exe" Query "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall" /K /F "*-001B-*0FF1CE}"`. – Compo Apr 24 '19 at 10:42
  • sure. Windows10 (64bit). – BlazeEigenmann Apr 24 '19 at 11:21
  • and the registry keys… – Compo Apr 24 '19 at 11:25
  • with regards to do those searches i am not sure how to implement. I can locate the Uninstall hive in RegEdit but nothing beyond that matches in terms of /K or /F or anything with the word 'off1ce in. – BlazeEigenmann Apr 24 '19 at 12:33
  • Open up a Command Prompt window, and paste each of the two searches in, one at a time, take the first returned line from any showing results, and paste them here ensuring you state which result belongs with which query. – Compo Apr 24 '19 at 12:36
  • ok sorry - ja i did try that but left the " in there - ok so i get 0 matches found for both searches – BlazeEigenmann Apr 24 '19 at 13:17
  • ok starting to understand the script a bit more here. it's almost like office doesnt exist on my machine haha - but it definitely does. is it because i have Office365 installed? is there perhaps a different search parameter? like instead of *OFF1CE it is *365 or something? – BlazeEigenmann Apr 24 '19 at 13:59
  • Well it appears that you've asked for a fix for 'my old code', for which I've provided an improved version, when it wasn't necessary. When I get access to a Windows PC, I may be able to update the code and test it, but essentially, my code is looking for information pertinent to an install of Microsoft Word, Product ID `001B`, from the Office registry key. It was used because, in my opinion it was unlikely that one would install an Office product but not include Microsoft Word. For now, you may get some luck from simply changing it from to `"*-001B-*0FF1CE}"` to `"*0FF1CE}"`. – Compo Apr 24 '19 at 14:38
  • As an additional note, the GUIDs are not created if the install is via a Click-to-Run installer as opposed to the usual full MSI versions. So if that is the case the entire code will be of no use to you. – Compo Apr 24 '19 at 14:48
  • hi yes we discovered that with regards to Click-To-Run thank you. and your improved version definitely helped me understand things more so it wasnt a waste at all thank you so much. and you are right - our clients all use MSWord so was definitely the way to go. many of them will have installed through click-to-run yes so will need to go with a different approach. I think maybe just two separate install files for now. The windows part is fine. Thank you kindly for your time. – BlazeEigenmann Apr 25 '19 at 07:53