Question

Good news: A major release is in the bag!

Bad news: I just found out (2 weeks too late) that some people don't have MSXML 6 on their machines and the new installer we're rolling out requires it.

Good news: We can distribute an MSI file to install MSXML

Bad news: There are three MSI files to choose from, one 'normal' one, one ending in ia64 and one ending in x64.

I have at my disposal, Delphi 7, C++ and um... Batch files... How do I make one of those handy Setup.exe's that choose the right MSI to launch automatically.

Was it helpful?

Solution

Short answer: Use the GetSystemInfo function of the Windows API to find out if the system is 32-bit or 64-bit.

Example code:

program Project1;

{$APPTYPE CONSOLE}

uses
  SysUtils, Windows;

var
  si: TSystemInfo;

const
  PROCESSOR_ARCHITECTURE_AMD64 = 9;
  PROCESSOR_ARCHITECTURE_IA64 = 6;
  PROCESSOR_ARCHITECTURE_INTEL = 0;
  PROCESSOR_ARCHITECTURE_UNKNOWN = $FFFF;

begin

  GetSystemInfo(si);
  case si.wProcessorArchitecture of
    PROCESSOR_ARCHITECTURE_AMD64: Writeln('AMD64');
    PROCESSOR_ARCHITECTURE_IA64: Writeln('IA64');
    PROCESSOR_ARCHITECTURE_INTEL: Writeln('Intel');
    PROCESSOR_ARCHITECTURE_UNKNOWN: Writeln('Unknown');
  end;

  Readln;

end.

The two most common outputs are 'Intel' (32-bit x86) and 'AMD64' (64-bit x64). In fact, you can more or less trust that you will get one of those.

Now, in reality, I believe that the above program will always return 'Intel' (32-bit x86) because all Delphi applications are 32-bit, and so they are emulated under a 64-bit Windows (using WOW64) -- there is no 64-bit release of the Delphi compiler and IDE.

So to obtain the true architecture of the system, regardless of emulation, you have to use the GetNativeSystemInfo function. There is no wrapper for this function, so you have to import it yourself from kernel32.dll.

program Project1;

{$APPTYPE CONSOLE}

uses
  SysUtils, Windows;

var
  si: TSystemInfo;

const
  PROCESSOR_ARCHITECTURE_AMD64 = 9;
  PROCESSOR_ARCHITECTURE_IA64 = 6;
  PROCESSOR_ARCHITECTURE_INTEL = 0;
  PROCESSOR_ARCHITECTURE_UNKNOWN = $FFFF;

procedure GetNativeSystemInfo(var lpSystemInfo: TSystemInfo); stdcall; external kernel32 name 'GetNativeSystemInfo';

begin

  GetNativeSystemInfo(si);
  case si.wProcessorArchitecture of
    PROCESSOR_ARCHITECTURE_AMD64: Writeln('AMD64');
    PROCESSOR_ARCHITECTURE_IA64: Writeln('IA64');
    PROCESSOR_ARCHITECTURE_INTEL: Writeln('Intel');
    PROCESSOR_ARCHITECTURE_UNKNOWN: Writeln('Unknown');
  end;

  Readln;

end.

OTHER TIPS

You can forget the IA64 which is for Itanium systems. I'd use a tool to create a setup (there are excellent free ones, like InnoSetup). They will detect which kind of system the setup up is running upon, and let you run the proper installer of msxml. If the tool supports the Windows Installer engine directly it can take advantage of merge modules (msm) to distribute needed runtimes, otherwise is pretty easy to run a msi from the installer. You could also write your own installer, but you get another app to write, test and mantain. I'd take advantage of existing ones for such a task.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top