Search code examples
registryinstallationwampinno-setupwampserver

Inno Setup check if WAMP is installed before proceeding


I'm using Inno Setup to create our installation wizard and it contains a WAMP installation in it. But according to others, double WAMP installation would harm WAMP itself. So I need to check if WAMP is installed before proceeding. Any ways on how to do this?


Solution

  • WAMP creates registry entries during the installation process. The installer is based on Inno Setup.

    There are 2 classes of registry entries:

    1 Individual:

    [Registry]
    
    Root: HKLM64; Subkey: "SOFTWARE\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers\"; 
    ValueName: "{app}\wampmanager.exe"; ValueType: String; ValueData: "RUNASADMIN"; 
    Check: "IsWin64"; MinVersion: 0.0,6.0; Flags: uninsdeletevalue uninsdeletekeyifempty 
    Root: HKLM32; Subkey: "SOFTWARE\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers\"; 
    ValueName: "{app}\wampmanager.exe"; ValueType: String; ValueData: "RUNASADMIN"; 
    Check: "Not IsWin64"; MinVersion: 0.0,6.0; Flags: uninsdeletevalue uninsdeletekeyifempty 
    

    2 Default Uninstallation information:

    HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{wampserver64}_is1 with path in InstallLocation

    That allows us to check if WAMP is installed and if Executable is present in installation folder (as an additional check).

    Example is based on 64-bit version of WAMP 3.0.6.

    It needs to be adjusted if support for both 32- and 64-bit versions is required.

    [Setup]
    ArchitecturesAllowed=x64
    ArchitecturesInstallIn64BitMode=x64[
    
    [Code]
    function CheckWAMPExists(): Boolean;
    var
      sInstPath: String;
      sInstallString: String;
    begin
      Result := False;
      sInstPath := 'SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{wampserver64}_is1';
      sInstallString := '';
      if not RegQueryStringValue(HKLM, sInstPath, 'InstallLocation', sInstallString) then
        RegQueryStringValue(HKCU, sInstPath, 'InstallLocation', sInstallString);
      if sInstallString <> '' then begin
        if FileExists(ExpandConstant(sInstallString) + 'wampmanager.exe') then
        MsgBox('WAMP found!' + #13#10 + 'Install location:' + #13#10 + sInstallString 
        + #13#10#13#10 + 'Installation will proceed!', mbInformation, MB_OK);
        Result := True;
      end
      else begin
        MsgBox('WAMP not found! Installation terminated.', mbInformation, MB_OK);
      end;
    end;
    
    function InitializeSetup(): Boolean;
    begin
        Result := CheckWAMPExists;
    end;