开发者

How to set automaticly DefaultDirName for previous Inno Setup installation?

开发者 https://www.devze.com 2023-02-26 19:45 出处:网络
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

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 hel开发者_JAVA百科p me, please?


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;


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;
0

精彩评论

暂无评论...
验证码 换一张
取 消