How to do Vista/UAC aware self-extract installer

2019-04-16 16:46发布

问题:

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?

回答1:

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.



回答2:

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.

                                 

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.

                      

References

  • HOWTO: Create a single EXE from your Java application