2

I distribute my software with a WinZip self-extract archive (SFX).
I am aware of this and that. But those doesn't seem to work for SFX scenarios.

While installing, the SFX unpacks and starts a contained program (written by me), that does the installation. This includes the creation of a registry entry for the programs list under the windows control panel. Further, the program has a manifest. So it should be "Vista-aware". The SFX-executable also includes a manifest.

The problem is that the Program Compatibility Assistant (PCA) throws its message "This program might not have installed correctly" anyway. So my customers tell me i'm a bad programmer...

I googled a lot, and read a lot about the PCA, including many Microsoft sites.
Those tell me to do:

  1. embed a manifest
  2. create registry entries for the programs list under the windows control panel

My manifest looks like this:

<?xml version="1.0" encoding="utf-8"?>
<asmv1:assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1" xmlns:asmv1="urn:schemas-microsoft-com:asm.v1" xmlns:asmv2="urn:schemas-microsoft-com:asm.v2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
    <security>
      <applicationRequestMinimum>
        <defaultAssemblyRequest permissionSetReference="Custom" />
        <PermissionSet class="System.Security.PermissionSet" version="1" Unrestricted="true" ID="Custom" SameSite="site" />
      </applicationRequestMinimum>
      <requestedPrivileges>
        <requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
      </requestedPrivileges>
    </security>
  </trustInfo>
</asmv1:assembly>

So where did i go wrong?
Are there any further things to do for the PCA?
Do the SFX executable have to include some other things?

Community
  • 1
  • 1
joe
  • 8,344
  • 9
  • 54
  • 80
  • Does SFX request elevation? Does it have `setup.exe` name? Is the manifest above from your installer or SFX? – Alexey Ivanov Feb 13 '12 at 07:32
  • Yes, the SFX requires elevated rights for the installation and it contains 'setup' in the name. The manifest above is my own, the SFX does contain a manifest too, but i don't know a way to change it. – joe Feb 13 '12 at 08:47
  • Are you sure the manifest in SFX has requestedExecutionLevel? If it had, there shouldn't be Compatibility Dialog shown. – Alexey Ivanov Feb 13 '12 at 08:59
  • Yes, the SFX manifest contains requestedExecutionLevel, level="requireAdministrator". The dialog comes up anyway. I think the PCA looks for a created entry in the windows control panel/programs, which is not written by the SFX. – joe Feb 13 '12 at 09:38
  • The thing is PCA is not applied when application has manifest with declared requestedExecutionLevel. Installer detection is performed only for apps that do not have manifest. So there must be something missing. Additionally, you can declare your app is compatible with Vista/7 via manifest. – Alexey Ivanov Feb 14 '12 at 08:08

2 Answers2

3

As was described in the other answer the key is setting the headers correctly in the PE (Portable Executable) portion of the file. We were encountering this problem while attempting to construct self extracting executables using SFX files & 7-zip.

The Portable Executable (PE) format is a file format for executables, object code, DLLs, FON Font files, and others used in 32-bit and 64-bit versions of Windows operating systems. The PE format is a data structure that encapsulates the information necessary for the Windows OS loader to manage the wrapped executable code.

NOTE: The PE file format is similar to ELF under Linux.

Building these files went smoothly, however when we tried to run our resulting files on Win7 we'd get the following dialog.

                                 ss #1

The biggest hint here is that this dialog is being thrown by PCA - Program Compatibility Assistant. This error is being thrown because PCA has either detected:

  1. No entry was added to the Add/Remove programs
  2. The Version field of the PE exectuable was correctly set

Fixing with PE Tools

In our case it seemed to be #2 that was causing the issue. So we downloaded PE Tools and opened the 7-zip SFX file. NOTE: We loaded the file 7zS.sfx.

Once loaded we changed the following version info from a 4 to a 6.

                      ss #2

References

slm
  • 15,396
  • 12
  • 109
  • 124
  • 1
    Thanks for your answer. In my case the missing part was #2, #1 (entry in programs) was still done. Like in most cases, any tool that has to be used manually is not useful when building the application automatically on a server. I did this already by setting the version field from within our build tool. This is done both with the zip file and the exe that is called by 7zip after extract. – joe Apr 01 '14 at 05:21
  • 1
    @joe - yes I did something similar too, we prebuilt the SFX file and then use it when assembling packages, but I thought it would be helpful to describe how to do this, since the other A didn't really go into specifics and we labored for a bit to figure out how to do this. – slm Apr 01 '14 at 05:24
  • Well, Anders' answer was the missing hint - enough to make the remaining way my own. That's what's counting here on SO. Taking a deeper look on the problem is good for people that will have the same problem in the future - that's what even count more here on SO! – joe Apr 01 '14 at 05:31
  • @joe - agreed, I generally like to add details as an A if the ones there don't spell things out enough to follow them. I come from the Unix world so am less versed in the whole PE windows world. So now this little corner of SO is clearer to me and hopefully others that may happen upon your Q in the future. – slm Apr 01 '14 at 05:42
  • 1
    You can also just use a hex editor and follow the structure on the wikipedia page: https://en.wikipedia.org/wiki/Portable_Executable - Basically find the value at 0x3C in your app (pointer to header), add 0x40 to that value (static offset of Major OS Version within PE header), and what you get is the offset to the Major OS Version, which I changed to 10 for windows 10. Worked me =D. Apparantly PE Tools is a hacker tool which is no longer available... – Simoyd May 25 '16 at 15:29
3

We fixed a similar issue in NSIS by setting a version field in the PE header to 6.0. I believe that was for our uninstaller but it might apply to your scenario as well.

Anders
  • 97,548
  • 12
  • 110
  • 164
  • 1
    Manipulating the SFX exe after building works great. Thank you, you saved my life! Is there any documentation about this? How did you come to this? – joe Feb 13 '12 at 08:21
  • Must the version 6.0 fit to the OS Version (Win Vista / Win 7) or is it your own? – joe Feb 13 '12 at 09:47
  • Updated link to NSIS source (the link above is broken and the edit queue is full ): https://sourceforge.net/p/nsis/code/5953/tree//NSIS/trunk/Source/build.cpp?diff=5937. – Hugh W Oct 03 '22 at 12:36