Inno: How to check Office Bitness

JohnPapa

Registered User.
Local time
Today, 23:59
Joined
Aug 15, 2010
Messages
1,117
Apologies in advance if this is not the correct place to post.

I use the following Inno code to install my software.

I would like to check if Office is installed and if it is installed to check the Bitness. Based on the Bitness I would like to install either the 32-bit Runtime or the 64-bit Runtime.

Do you know how to check for the presence of Office, which Office and its Bitness?

Code:
; Script generated by the Inno Setup Script Wizard.
; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES!

#define MyAppName "Visual Dentist"
#define MyAppVersion "20.0"
#define MyAppPublisher "Kosmos Business Systems Ltd"
#define MyAppURL "https://www.VisualDentist.com"
#define MyAppExeName "vd5Init.accde"
#define MyAppIcoName "logo.ico"

[Setup]
; NOTE: The value of AppId uniquely identifies this application.
; Do not use the same AppId value in installers for other applications.
; (To generate a new GUID, click Tools | Generate GUID inside the IDE.)
AppId={{A2E41031-5E7B-4069-833F-581EED5AD9CD}
AppName={#MyAppName}
AppVersion={#MyAppVersion}
AppVerName={#MyAppName} {#MyAppVersion}
AppPublisher={#MyAppPublisher}
AppPublisherURL={#MyAppURL}
AppSupportURL={#MyAppURL}
AppUpdatesURL={#MyAppURL}
DefaultDirName= "C:\VisualDentist"
UsePreviousAppDir=yes
DisableDirPage=no
DefaultGroupName=VisualDentist {#MyAppVersion}
DisableProgramGroupPage=yes
OutputBaseFilename=VisualDentistSetup
Compression=lzma
SolidCompression=yes
PrivilegesRequired=admin
;LicenseFile=C:\Inno\setup\VisualDentistLicense.txt

[Languages]
Name: "english"; MessagesFile: "compiler:Default.isl"

[Tasks]
Name: "desktopicon"; Description: "{cm:CreateDesktopIcon}"; GroupDescription: "{cm:AdditionalIcons}"; Flags: unchecked

[Files]
Source: "C:\Inno\Setup64\vd5Init.accde"; DestDir: "{app}"; Flags: ignoreversion replacesameversion
;Source: "C:\Inno\Setup64\VD32.accde"; DestDir: "{app}"; Flags: ignoreversion replacesameversion
Source: "C:\Inno\Setup64\VD64.accde"; DestDir: "{app}"; Flags: ignoreversion replacesameversion
Source: "C:\Inno\Setup64\vd5_be.accdb"; DestDir: "{app}"; Flags: ignoreversion
Source: "C:\Inno\Setup64\A365Runtime64.exe"; DestDir: "{app}"; Flags: ignoreversion
Source: "C:\Inno\Setup64\logo.ico"; DestDir: "{app}"; Flags: ignoreversion
Source: "C:\Inno\Setup64\VD-Serial.txt"; DestDir: "{app}"; Flags: ignoreversion

[Icons]
Name: "{autodesktop}\VisualDentist"; Filename: "{app}\vd5Init.accde"; Parameters: "/runtime"; IconFilename: "{app}\{#MyAppIcoName}"; Tasks: desktopicon

[Code]
function PrepareToInstall(var NeedsRestart: Boolean): String;
 var
  CurVer: string;
  key: string;
  ResultCode: Integer;
 begin
   if RegQueryStringValue(HKEY_CLASSES_ROOT, '\Access.Application\CurVer','', CurVer) and ( CurVer = 'Access.Application.15' ) then begin
    // Successfully read the value
    //  MsgBox('Access Version: ' + CurVer ,mbInformation, MB_OK);
    end else begin
        ExtractTemporaryFile('A365Runtime64.exe');
        if Exec(ExpandConstant('{tmp}\A365Runtime64.exe'), '', '', SW_HIDE, ewWaitUntilTerminated, ResultCode) then begin

            //msgbox('AccessRuntime already installed or completed installing successfully.', mbInformation, MB_OK);
        end else begin
            msgbox('AccessRuntime installer failed please contact support.' + SysErrorMessage(ResultCode), mbInformation, MB_OK );     
        end; 
    end;
end;

[Run]
Filename: "{app}\vd5Init.accde"; Description: "Open Visual Dentist"; Flags: postinstall shellexec skipifsilent ; Parameters: "/runtime"
 
I am sure @isladogs posted something that checks bitness, but cannot find it at the moment.
Registry would be where I would start looking for Office.

Edit: Offered by ChatGPT. Up to you to test.
Code does not work for me. :(
Code:
Sub CheckOfficeBitness()
    Dim bitness As String
    Dim isInstalled As Boolean
   
    ' Check 64-bit Office (on 64-bit Windows)
    bitness = GetOfficeBitness("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Office\ClickToRun\Configuration", "Platform")
    If bitness <> "" Then
        MsgBox "Office is installed. Bitness: " & bitness, vbInformation
        Exit Sub
    End If

    ' Check 32-bit Office on 64-bit Windows (Wow6432Node)
    bitness = GetOfficeBitness("HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Office\ClickToRun\Configuration", "Platform")
    If bitness <> "" Then
        MsgBox "Office is installed. Bitness: " & bitness, vbInformation
        Exit Sub
    End If
   
    MsgBox "Microsoft Office does not appear to be installed.", vbExclamation
End Sub

Private Function GetOfficeBitness(regPath As String, valueName As String) As String
    On Error Resume Next
    Dim shell As Object
    Set shell = CreateObject("WScript.Shell")
   
    Dim value As String
    value = shell.RegRead(regPath & "\" & valueName)
   
    If Err.Number = 0 Then
        GetOfficeBitness = value
    Else
        GetOfficeBitness = ""
        Err.Clear
    End If
End Function
 
Last edited:
With the above code I get
? err.Number
-2147024894

and I am 32bit on win64.

However, it should get you started?

1749832231549.png
 
If you persevere with ChatGPT, you not only learn something, but eventually get code that works.
This works for me and provides correct answer.

Code:
Function Read64BitRegistryValue(regKey As String, valueName As String) As String
    Dim cmd As String
    Dim output As String
    Dim wsh As Object
    Dim execObj As Object
    Dim inputLine As String
    
    ' Command to read from the 64-bit registry view using /reg:64
    cmd = "reg query """ & regKey & """ /v " & valueName & " /reg:64"

    Set wsh = CreateObject("WScript.Shell")
    Set execObj = wsh.Exec("%ComSpec% /c " & cmd)

    Do While Not execObj.StdOut.AtEndOfStream
        inputLine = execObj.StdOut.ReadLine
        If InStr(inputLine, valueName) > 0 Then
            ' Extract the value after the last space
            output = Trim(Split(inputLine, valueName)(1))
            output = Trim(Mid(output, InStr(output, " "))) ' strip extra whitespace
            Read64BitRegistryValue = output
            Exit Function
        End If
    Loop

    Read64BitRegistryValue = "" ' fallback
End Function
Sub Test64BitRead()
    Dim keyPath As String
    Dim valueName As String
    Dim result As String

    keyPath = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Office\ClickToRun\Configuration"
    valueName = "Platform"

    result = Read64BitRegistryValue(keyPath, valueName)

    If result <> "" Then
        MSGBOX "Office Platform (bitness): " & result
    Else
        MSGBOX "Value not found or error accessing 64-bit registry.", vbExclamation
    End If
End Sub
 
This works for me
Code:
Sub CheckOfficeBitness()
    Dim bitness As String
#If Win64 Then
    bitness = "64-bit Office"
#Else
    bitness = "32-bit Office"
#End If
    MsgBox "This is " & bitness, vbInformation
End Sub
 
Jack beat me to it.
I use effectively identical code as one small part of my Access Version Checker app (standalone or add-in):

Code:
Function IsOfficex64()

#If Win64 Then
  IsOfficex64 = "64-bit"
#Else
  IsOfficex64 = "32-bit"
#End If

End Function

1749834590705.png


 
I believe there is a misunderstanding. There is no problem checking for bitness using VBA.

If you look at my original post #1, the question is how to do it using Inno.
 
After some further research the following might work. Will test it out.

Code:
function GetOfficeBitness(): String;
var
  Bitness: String;
begin
  if RegQueryStringValue(HKEY_LOCAL_MACHINE, 'SOFTWARE\Microsoft\Office\ClickToRun\Configuration', 'Platform', Bitness) then
  begin
    Result := Bitness;
  end
  else
  begin
    Result := 'Unknown';
  end;
end;

You need to check the correct Registry setting. May vary...
 
Inno script provided by CoPilot:
Code:
[Code]
function GetOfficeBitness(): string;
var
  RegKey: string;
  Bitness: string;
begin
  Bitness := 'Unknown';

  // Check for 64-bit Office
  RegKey := 'SOFTWARE\Microsoft\Office\';
  if RegQueryStringValue(HKLM, RegKey + '16.0\Access\Database Engine', 'Bitness', Bitness) then
    Result := Bitness
  else if RegQueryStringValue(HKLM, RegKey + '15.0\Access\Database Engine', 'Bitness', Bitness) then
    Result := Bitness
  else if RegQueryStringValue(HKLM, RegKey + '14.0\Access\Database Engine', 'Bitness', Bitness) then
    Result := Bitness
  else
    begin
      // Check for 32-bit Office (Wow6432Node for 64-bit Windows)
      RegKey := 'SOFTWARE\WOW6432Node\Microsoft\Office\';
      if RegQueryStringValue(HKLM, RegKey + '16.0\Access\Database Engine', 'Bitness', Bitness) then
        Result := Bitness
      else if RegQueryStringValue(HKLM, RegKey + '15.0\Access\Database Engine', 'Bitness', Bitness) then
        Result := Bitness
      else if RegQueryStringValue(HKLM, RegKey + '14.0\Access\Database Engine', 'Bitness', Bitness) then
        Result := Bitness
    end;

  if Bitness = '' then
    Result := 'Unknown';
end;

procedure InitializeWizard;
begin
  MsgBox('Microsoft Office Bitness: ' + GetOfficeBitness(), mbInformation, MB_OK);
end;

This script checks multiple versions of Microsoft Office and retrieves the "Bitness" value from the registry. If Office is installed, it returns either "32-bit" or "64-bit". Otherwise, it returns "Unknown".
 
Inno script provided by CoPilot:
Code:
[Code]
function GetOfficeBitness(): string;
var
  RegKey: string;
  Bitness: string;
begin
  Bitness := 'Unknown';

  // Check for 64-bit Office
  RegKey := 'SOFTWARE\Microsoft\Office\';
  if RegQueryStringValue(HKLM, RegKey + '16.0\Access\Database Engine', 'Bitness', Bitness) then
    Result := Bitness
  else if RegQueryStringValue(HKLM, RegKey + '15.0\Access\Database Engine', 'Bitness', Bitness) then
    Result := Bitness
  else if RegQueryStringValue(HKLM, RegKey + '14.0\Access\Database Engine', 'Bitness', Bitness) then
    Result := Bitness
  else
    begin
      // Check for 32-bit Office (Wow6432Node for 64-bit Windows)
      RegKey := 'SOFTWARE\WOW6432Node\Microsoft\Office\';
      if RegQueryStringValue(HKLM, RegKey + '16.0\Access\Database Engine', 'Bitness', Bitness) then
        Result := Bitness
      else if RegQueryStringValue(HKLM, RegKey + '15.0\Access\Database Engine', 'Bitness', Bitness) then
        Result := Bitness
      else if RegQueryStringValue(HKLM, RegKey + '14.0\Access\Database Engine', 'Bitness', Bitness) then
        Result := Bitness
    end;

  if Bitness = '' then
    Result := 'Unknown';
end;

procedure InitializeWizard;
begin
  MsgBox('Microsoft Office Bitness: ' + GetOfficeBitness(), mbInformation, MB_OK);
end;

This script checks multiple versions of Microsoft Office and retrieves the "Bitness" value from the registry. If Office is installed, it returns either "32-bit" or "64-bit". Otherwise, it returns "Unknown".
Many thanks, this should do it.
 
Inno script provided by CoPilot:
Code:
[Code]
function GetOfficeBitness(): string;
var
  RegKey: string;
  Bitness: string;
begin
  Bitness := 'Unknown';

  // Check for 64-bit Office
  RegKey := 'SOFTWARE\Microsoft\Office\';
  if RegQueryStringValue(HKLM, RegKey + '16.0\Access\Database Engine', 'Bitness', Bitness) then
    Result := Bitness
  else if RegQueryStringValue(HKLM, RegKey + '15.0\Access\Database Engine', 'Bitness', Bitness) then
    Result := Bitness
  else if RegQueryStringValue(HKLM, RegKey + '14.0\Access\Database Engine', 'Bitness', Bitness) then
    Result := Bitness
  else
    begin
      // Check for 32-bit Office (Wow6432Node for 64-bit Windows)
      RegKey := 'SOFTWARE\WOW6432Node\Microsoft\Office\';
      if RegQueryStringValue(HKLM, RegKey + '16.0\Access\Database Engine', 'Bitness', Bitness) then
        Result := Bitness
      else if RegQueryStringValue(HKLM, RegKey + '15.0\Access\Database Engine', 'Bitness', Bitness) then
        Result := Bitness
      else if RegQueryStringValue(HKLM, RegKey + '14.0\Access\Database Engine', 'Bitness', Bitness) then
        Result := Bitness
    end;

  if Bitness = '' then
    Result := 'Unknown';
end;

procedure InitializeWizard;
begin
  MsgBox('Microsoft Office Bitness: ' + GetOfficeBitness(), mbInformation, MB_OK);
end;

This script checks multiple versions of Microsoft Office and retrieves the "Bitness" value from the registry. If Office is installed, it returns either "32-bit" or "64-bit". Otherwise, it returns "Unknown".
Does not seem to find the specified Registry folder and does not return the bitness
 
Do the folders/values exist?
When I was trying with ChatGPT, it advised of redirection by some programs. So whilst x86 was in the Platform entry, the Shell was being redirected to the WOW64 key, where that value did not exist.

First 'bitness' I can find is at Computer\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Office\ClickToRun\REGISTRY\MACHINE\Software\Microsoft\Office\16.0\Outlook
 
Last edited:
Searching for the following works

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Office\<version>\Outlook

In line with gasman
 
Well you need to see if the entries exist in the first place?
I have x86 in the Platform key.
 
there is another version from CoPilot:
Code:
[Code]
const
  // Value returned by GetBinaryType for a 64-bit executable.
  SCS_64BIT_BINARY = 6;

  // Registry key where Office application paths are stored.
  AppPathsKey = 'SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\MSACCESS.EXE';

function GetBinaryType(exePath: string; var BinaryType: Integer): Boolean;
  external 'GetBinaryTypeW@kernel32.dll stdcall';

// Returns True if the Office executable is 64-bit, False if 32-bit (or not found)
function IsOffice64Bit(): Boolean;
var
  ExePath: string;
  BinaryType: Integer;
begin
  Result := False;
  // Query the registry key for the Office executable path.
  if RegQueryStringValue(HKLM, AppPathsKey, '', ExePath) then
  begin
    // If the executable path was found, use GetBinaryType to check its bitness.
    if GetBinaryType(ExePath, BinaryType) then
    begin
      // SCS_64BIT_BINARY (which is defined as 6) indicates a 64-bit binary.
      Result := (BinaryType = SCS_64BIT_BINARY);
    end;
  end;
end;

// Example usage: display a message box in the wizard showing Office bitness.
procedure InitializeWizard;
begin
  if IsOffice64Bit() then
    MsgBox('Microsoft Office is installed as 64-bit.', mbInformation, MB_OK)
  else
    MsgBox('Microsoft Office is installed as 32-bit or was not found.', mbInformation, MB_OK);
end;
 
there is another version from CoPilot:
Code:
[Code]
const
  // Value returned by GetBinaryType for a 64-bit executable.
  SCS_64BIT_BINARY = 6;

  // Registry key where Office application paths are stored.
  AppPathsKey = 'SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\MSACCESS.EXE';

function GetBinaryType(exePath: string; var BinaryType: Integer): Boolean;
  external 'GetBinaryTypeW@kernel32.dll stdcall';

// Returns True if the Office executable is 64-bit, False if 32-bit (or not found)
function IsOffice64Bit(): Boolean;
var
  ExePath: string;
  BinaryType: Integer;
begin
  Result := False;
  // Query the registry key for the Office executable path.
  if RegQueryStringValue(HKLM, AppPathsKey, '', ExePath) then
  begin
    // If the executable path was found, use GetBinaryType to check its bitness.
    if GetBinaryType(ExePath, BinaryType) then
    begin
      // SCS_64BIT_BINARY (which is defined as 6) indicates a 64-bit binary.
      Result := (BinaryType = SCS_64BIT_BINARY);
    end;
  end;
end;

// Example usage: display a message box in the wizard showing Office bitness.
procedure InitializeWizard;
begin
  if IsOffice64Bit() then
    MsgBox('Microsoft Office is installed as 64-bit.', mbInformation, MB_OK)
  else
    MsgBox('Microsoft Office is installed as 32-bit or was not found.', mbInformation, MB_OK);
end;
This may be a better way. I would change

AppPathsKey = 'SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\ACCESS.EXE';

to

AppPathsKey = 'SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\OUTLOOK.EXE';

In my case I need to install the correct Access Runtime, so I am not really interested in whether Access is installed or not. All I am interested is whether the Office components installed are 32-bit or 64-bit and appropriately install the correct Runtime.
 
In my case I need to install the correct Access Runtime, so I am not really interested in whether Access is installed or not. All I am interested is whether the Office components installed are 32-bit or 64-bit and appropriately install the correct Runtime.
Bear in mind that you cannot (or at least should not) install the same version of Access runtime when the full copy of that version is already installed.
e.g. you cannot have both 2016 & 2016 Runtime or 365 / 365 Runtime

You can of course install different versions of Access Runtime and full Access (just as you can install multiple versions of full Access)
 
Last edited:
Bear in mind that you cannot (or at least should not) install the same version of Access runtime when the full copy of that version is already installed.
e.g. you cannot have both 2016 & 2016 Runtime or 365 / 365 Runtime

You can of course install different versions of Access Runtime and full Access (just as you can install multiple versions of full Access)
Yes, good point to remember
 

Users who are viewing this thread

Back
Top Bottom