Setup.exe Bootstrap Sample and APPVER

On an internal alias – which inspires many of my blog entries – someone
wasn’t able to run the sample bootstrap executable setup.exe, found in
the Samples/SysMgmt/Msi/Setup.exe folder in your
Platform SDK installation
root. The error was "setup.exe is not a valid Win32 application" when run on
Windows 2000 but the sample worked fine on Windows XP. Right away it would seem
that something in the

PE headers
of the sample something is wrong. Take a look at part of the
dumpbin.exe
output:

OPTIONAL HEADER VALUES
             10B magic # (PE32)
            7.10 linker version
            A800 size of code
            6200 size of initialized data
               0 size of uninitialized data
            5566 entry point (00405566)
            1000 base of code
            C000 base of data
          400000 image base (00400000 to 00414FFF)
            1000 section alignment
             200 file alignment
            4.00 operating system version
            0.00 image version
            5.01 subsystem version
               0 Win32 version
           15000 size of image
             400 size of headers
           1EF48 checksum
               2 subsystem (Windows GUI)

Because the subsystem version is 5.01 the executable will run on a minimum
operating system of Windows XP. So how did this happen?

If you build the setup.exe sample using the build environment consoles
also installed with the Platform SDK, the environment variable APPVER is set
according to which OS you pick in the current options. If you started the
shortcut "Set Windows XP 32-bit Build Environment (Retail)" then APPVER is
defined as 5.01. This variable is used many places in the win32.mak file
included by Makefile in the setup.exe sample directory.
Particularilily this is why the subsystem was set to 5.01:

# Windows 98 needs subsystem
version set to 4.10 for version 5.0 features.
!IF ("$(APPVER)" == "5.0") && (("$(TARGETOS)" == "BOTH") || ("$(TARGETOS)" ==
"WIN95"))
EXEVER = 4.10
!ELSE
EXEVER = $(APPVER)
!ENDIF

# ———————————————

# for Windows applications
conlflags = $(lflags) -subsystem:console,$(EXEVER)
guilflags = $(lflags) -subsystem:windows,$(EXEVER)

So when building setup.exe make sure you set APPVER according to your
platform requirements. You can either start the appropriate build environment
console or after starting the console set APPVER to 4.0, 5.0, 5.01,
or 5.02. Future versions of the Platform SDK for future versions of Windows will
likely include support for additional values.