views:

133

answers:

2

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.

+2  A: 

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.
Andreas Rejbrand
By the way: in the last example it looks kind of the block `begin ... end` is the implementation of `GetNativeSystemInfo`. This is **not** the case. The block is the console program. In a more regular unit, you would write `procedure GetNativeSystemInfo(var lpSystemInfo: TSystemInfo); stdcall;` in the `interface` section and `procedure GetNativeSystemInfo; external kernel32 name 'GetNativeSystemInfo';` in the `implementation` section. Then, from any unit using this unit, you can call `GetNativeSystemInfo`, the same way you call `GetSystemInfo`.
Andreas Rejbrand
Thanks a metric ton, I'll mark this as the answer as soon as I run your code.
Peter Turner
+1  A: 

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.

ldsandon
Point well taken, good to know what IA64 is because if I were to forgot you can bet that 7 of our clients would need it!
Peter Turner
Also, gotta mention that GetNativeSystemInfo isn't in Win2k, but if they've got win2k then they hopefully haven't got a 64 bit processor so what the hey. I found this handy as wellhttp://msdn.microsoft.com/en-us/library/ms724429%28VS.85%29.aspx
Peter Turner
Although, I should have mentioned it as a comment to the other guy's post...
Peter Turner

related questions