2

my previous installation (A) in Inno Setup has AppID={{8ADA0E54-F327-4717-85A9-9DE3F8A6D100}.

I have another installation (B) with different AppID and I want to install it into the same directory as installation (A).

How do I get automaticly DefaultDirName? I don't want to use the same AppID, because when I uninstall the installation (B) and installation (A) stays installed, it will delete AppID string from registry (installation (A) string).

Can you help me, please?

Jiri
  • 23
  • 1
  • 3

2 Answers2

6

You'll probably need some code to do what you want. You'll also need a way to find the installation directory of Application A. Here's some code that I've used

[Setup]
DefaultDirName={code:GetDefaultDir}

[Code]
function GetDefaultDir(def: string): string;
var
sTemp : string;
begin
    //Set a defualt value so that the install doesn't fail.  
    sTemp := ExpandConstant('{pf}') + '\MyCompany\MyAppA';

    //We need to get the current install directory.  
    if RegQueryStringValue(HKEY_LOCAL_MACHINE, 'Software\MyCompany\Products\MyAppNameA',
     'InstallDir', sTemp) then
     begin
    //We found the value in the registry so we'll use that.  Otherwise we use the default 
     end;
    Result := sTemp;
end;
mirtheil
  • 8,952
  • 1
  • 30
  • 29
  • This would only work if the previous setup recorded such a key. If not, previous installation's AppID can be queried for the `'Inno Setup: App Path` value. The key would be `'HKLM\Software\Microsoft\Windows\CurrentVersion\Uninstall\'+AppID+'_is1'`. Not much difference, so +1. – Sertac Akyuz Apr 19 '11 at 21:05
  • Thank you, guys. I will try it tomorrow and let you know. – Jiri Apr 19 '11 at 21:45
  • I tried this code and it doesn't work [Code] function GetDefaultDir(def: string): string; var sTemp : string; begin //Set a defualt value so that the install doesn't fail. sTemp := ExpandConstant('C:'); //We need to get the current install directory. if RegQueryStringValue(HKEY_LOCAL_MACHINE, 'Software\Microsoft\Windows\CurrentVersion\Uninstall\{8ADA0E54-F327-4717-85A9-9DE3F8A6D100}_is1', 'InstallDir', sTemp) then begin //We found the value in the registry so we'll use that. Otherwise we use the default end; Result := sTemp; end; – Jiri Apr 20 '11 at 08:16
  • I am sorry about post above, I don't know how to use tags in here. I am running Win7 64bit and string for AppID is this one: HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\{8ADA0E54-F327-4717-85A9-9DE3F8A6D100}_is1 – Jiri Apr 20 '11 at 08:22
  • I found another code, but it doesn't work too http://www.vbforums.com/showthread.php?t=533117 [Code] function GetInstallDirectory(S: String) : String; var installDirectory : String; begin if RegQueryStringValue(HKEY_LOCAL_MACHINE, 'SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\', '{8ADA0E54-F327-4717-85A9-9DE3F8A6D100}_is1', installDirectory) then //SUCCESS READING VALUE Result := installDirectory else //FAILED READING VALUE Result := ExpandConstant('C:'); end; – Jiri Apr 20 '11 at 10:47
  • You say it doesn't work. What do you mean? Does it not the value and uses the Default? Looking at the code, it seems to be looking at the wrong registry value. Change your code from "InstallDir" to "InstallLocation". – mirtheil Apr 20 '11 at 11:16
  • I compile the setup and run it. It doesn't find installed folder and set Install Directory to C: (that means it failed). I will try your suggestion. Thank you for helping me. – Jiri Apr 20 '11 at 11:48
  • I changed '{8ADA0E54-F327-4717-85A9-9DE3F8A6D100}_is1', installDirectory value to '{8ADA0E54-F327-4717-85A9-9DE3F8A6D100}_is1', InstallLocation and it says Unknown Identifier 'InstallLocation' – Jiri Apr 20 '11 at 11:57
  • Code: [Setup] DefaultDirName={code:GetDefaultDir} [Code] function GetDefaultDir(def: string): string; var sTemp : string; begin //Set a defualt value so that the install doesn't fail. sTemp := ExpandConstant('C:'); //We need to get the current install directory. if RegQueryStringValue(HKEY_LOCAL_MACHINE, 'Software\Microsoft\Windows\CurrentVersion\Uninstall\{8ADA0E54-F327-4717-85A9-9DE3F8A6D100}_is1', 'InstallLocation', sTemp) then begin //We found the value in the registry so we'll use that. Otherwise we use the default end; Result := sTemp; end; – Jiri Apr 20 '11 at 12:35
  • A lot of confusing comments here, but basically if you want the "current install directory" key to be in the registry, you need to add it, see: http://www.jrsoftware.org/ishelp/index.php?topic=setup_outputbasefilename. This seems to me a bit cleaner than using the "Uninstall" key. – j b Feb 10 '17 at 10:52
4

I developed the following code to find the installation directory based on AppID. It accommodates per-user registry entries as well as those for the entire machine. It has been tested on Windows 7 Enterprise on a domain and in a Virtual PC XP Professional machine:

[code]
const
   PreviousAppID = '8ADA0E54-F327-4717-85A9-9DE3F8A6D100';
   AppFolder     = 'SomeFolder';

   UninstallPath = 'Software\Microsoft\Windows\CurrentVersion\Uninstall\{'
                  + PreviousAppID + '}_is1';

   // Some posts have 'InstallDir', but I have never observed that
   InstallKey    = 'InstallLocation';

function GetDefaultDir( Param: String ) : String;
var
   UserSIDs: TArrayOfString;
   I:        Integer;

begin
   // Check if the current user installed it
   if RegQueryStringValue( HKEY_CURRENT_USER, UninstallPath,
                           InstallKey, Result ) then

   // Current user didn't install it.  Did someone else?
   else if RegGetSubkeyNames( HKEY_USERS, '', UserSIDs ) then begin
      for I := 0 to GetArrayLength( UserSIDs ) - 1 do begin
         if RegQueryStringValue( HKEY_USERS, UserSIDs[I] + '\' + UninstallPath,
                                 InstallKey, Result ) then break;
      end;  
   end;

   // Not installed per-user
   if Result = '' then begin
      // What about installed for the machine?
      if RegQueryStringValue( HKEY_LOCAL_MACHINE, UninstallPath,
                              InstallKey, Result ) then

      // Doesn't appear to be installed, as admin default to Program Files
      else if IsAdminLoggedOn() then begin
         Result := ExpandConstant('{pf}\') + AppFolder;

      // As non-admin, default to Local Application Data
      end else begin
         Result := ExpandConstant('{localappdata}\') + AppFolder;
      end;
   end;
end;
Terrance
  • 398
  • 3
  • 9