Determine Windows version in Inno Setup

Issue

I’m using Inno Setup to change the recycle bin in the OS. I need to make some cases for if the user is running Windows 7 or Windows XP. I try using:

if not FileExists(winDir + '\System32\imageres.dll') then
  if not FileExists(winDir + '\System32\shell32.dll') then
    installError(3);

But it seems like it can’t find imageres.dll or shell32.dll even though I’ve verified they exist. What am I doing wrong? Or can I check the Windows version another way?

Solution

You should use the GetWindowsVersionEx function. It fills a TWindowsVersion record:

TWindowsVersion = record
  Major: Cardinal;             // Major version number
  Minor: Cardinal;             // Minor version number
  Build: Cardinal;             // Build number
  ServicePackMajor: Cardinal;  // Major version number of service pack
  ServicePackMinor: Cardinal;  // Minor version number of service pack
  NTPlatform: Boolean;         // True if an NT-based platform
  ProductType: Byte;           // Product type (see below)
  SuiteMask: Word;             // Product suites installed (see below)
end;

There are a lot of other related functions. See below ‘System functions’ at this page.

Answered By – Andreas Rejbrand

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published