Inno Setup – How to rename installation folder for new versions – moving from side-by-side to a single folder installations?

I use a side-by-side installation of my software where each new version is installed into a separate folder, for example “MySoftware2”, “MySoftware3” etc. This was not a good idea and I would like to move to a single folder installation where all installations and updates would be into "MySoftware" folder (without version numbers).

For all fresh installs the folder would be DefaultDirName={pf}MySoftware

But what about the auto updates from the previous versions of the software (for example from v3 to v4)? I guess those should be installed into existing folder (“MySoftware3”) and then renamed? How can Inno know the existing folder and could Inno rename the installation directory after the installation?

Any idea how to do this properly? Thanks.

8

To rename a installation folder, you can use RenameFile function from CurStepChanged(ssPostInstall). That’s the easy part.

But you also need to update the uninstall registry information. That’s much more work.

Something like this will do.

#define AppId "My Program"

[Setup]
AppId={#AppId}
[Code]

const
  OldDirName = 'MySoftware3';
  NewDirName = 'MySoftware';
  InnoSetupReg =
    'SoftwareMicrosoftWindowsCurrentVersionUninstall{#AppId}_is1';

var
  Path, NewPath: string;
  RootKey: Integer;

function CheckRegistry(
  ValueName: string; var P: Integer; var Value: string): Boolean;
begin
  if not RegQueryStringValue(RootKey, InnoSetupReg, ValueName, Value) then
  begin
    Log(Format('Cannot find uninstall registry value "%s" in key %s', [
      ValueName, InnoSetupReg]));
    Result := False;
  end
    else
  begin
    P := Pos(Lowercase(Path), Lowercase(Value));
    Result := (P > 0);
    if not Result then
    begin
      Log(Format(
        'Uninstall registry value "%s" in key %s "%s" ' +
          'does not contain the installation path "%s"', [
        ValueName, InnoSetupReg, Value, Path]));
    end;
  end
end;

procedure UpdateRegistry(ValueName: string);
var
  Value, NewValue: string;
  P: Integer;
begin
  if CheckRegistry(ValueName, P, Value) then
  begin
    NewValue :=
      Copy(Value, 1, P - 1) +
      NewPath +
      Copy(Value, P + Length(Path), Length(Value) - P - Length(Path) + 1);
    if not RegWriteStringValue(RootKey, InnoSetupReg, ValueName, NewValue) then
    begin
      Log(Format('Cannot write uninstall registry value "%s" in key %s', [
        ValueName, InnoSetupReg]));
    end
      else
    begin
      Log(Format('Updated uninstall registry value "%s" from "%s" to "%s"', [
        ValueName, Value, NewValue]));
    end;
  end;
end;

procedure CurStepChanged(CurStep: TSetupStep);
var
  Value: string;
  P: Integer;
begin
  Log(Format('CurStepChanged %d', [CurStep]));
  if CurStep = ssPostInstall then
  begin
    Path := ExpandConstant('{app}');
    if CompareText(ExtractFileName(Path), OldDirName) = 0 then
    begin
      Log(Format(
        'Program was installed to old folder name "%s", trying to rename...', [
          Path]));
      NewPath := ExtractFilePath(Path) + NewDirName;

      if IsAdminInstallMode then RootKey := HKLM
        else RootKey := HKCU;

      if CheckRegistry('UninstallString', P, Value) then
      begin
        if not RenameFile(Path, NewPath) then
        begin
          Log('Failed to rename');
        end
          else
        begin
          Log('Renamed, updating uninstall registry information...');
          UpdateRegistry('UninstallString');
          UpdateRegistry('QuietUninstallString');
          UpdateRegistry('DisplayIcon');
          UpdateRegistry('Inno Setup: App Path');
          UpdateRegistry('InstallLocation');
          Log('Installation path rename done');
        end;
      end;
    end;
  end;
end;

Though note that it relies old name not to be part of the new name, like you have it now (MySoftware => MySoftware3). Otherwise it would keep renaming with every update.

2

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật