(1) How to refuse to install if another install hasn't been uninstalled and (2) How to rename...

133 views
Skip to first unread message

alan_ka...@s4.com

unread,
May 8, 2020, 11:05:20 AM5/8/20
to innosetup
I've got a setup that I want to change the product name of.

Obviously a new install is not the problem, but upgrading an older install is:  It will have a new program files directory name, a new programdata directory name, and even files in the programdata directory will need to be renamed.

Ideal would be a new setup that somehow deals with possibility that the older version is still installed.  It would basically need to uninstall the old version, rename the old programdata directory assuming that it exists and the new one doesn't exist, and then rename some of the files in the programdata directory to their new names, again assuming the new name doesn't already exist.

What I don't want is errors in setup because something got stuck half way through the install/upgrade process.

I don't mind making the user uninstall the old version first if that makes this easier - that would require me having setup check to see if the old version is installed and refusing to install the new one until it is uninstalled.

I am thinking the new setup version should have a new GUID, but I am open to ideas on how to best approach this.  Thanks!

alan_ka...@s4.com

unread,
May 14, 2020, 10:38:57 AM5/14/20
to innosetup
I think I figured out how to do this, here is what I did:

function IsOldVersionInstalled: Boolean;
begin
  Result := FileExists(ExpandConstant('{pf}')+'\old program dir\oldexename.exe');
end;

function InitializeSetup: Boolean;
begin
  Result := True;
  if IsOldVersionInstalled then
  begin
    MsgBox('You must uninstall the previous version before installing.', mbError, MB_OK);
    Result := False;
    Exit;
  end;
end;

function PrepareToInstall(var NeedsRestart: Boolean): String;
begin
{ do we need to rename dir/files }
if DirExists(expandconstant('{commonappdata}')+'\oldname') and not DirExists(expandconstant('{commonappdata}')+'\newname') then
  begin
    if not RenameFile(expandconstant('{commonappdata}')+'\oldname', expandconstant('{commonappdata}')+'\newname') then
    begin
      Result := 'Unable to rename old programdata directory.';
      Exit;
    end;
  end;

{try to rename oldname.log}
if FileExists(expandconstant('{commonappdata}')+'\newname\oldname.log') and not FileExists(expandconstant('{commonappdata}')+'\newname\newname.log') then
  begin
    if not RenameFile(expandconstant('{commonappdata}')+'\newname\oldname.log', expandconstant('{commonappdata}')+'\newname\newname.log') then
      begin
        Result := 'Unable to rename oldname.log.';
        Exit;
      end;
  end;  

end;


Gavin Lambert

unread,
May 14, 2020, 8:34:18 PM5/14/20
to inno...@googlegroups.com
On 15/05/2020 02:38, alan_ka...@s4.com wrote:
> I think I figured out how to do this, here is what I did:
>
> |
> function IsOldVersionInstalled: Boolean;
> begin
>   Result := FileExists(ExpandConstant('{pf}')+'\old program
> dir\oldexename.exe');
> end;

Another option is to check for the uninstall registry entry. That may
be more reliable if the old version allowed the installation path to be
changed. (Or less reliable if someone copied the files manually without
running the installer.)

Also: it's recommended to put at least the first backslash following the
constant inside the ExpandConstant call -- it's usually easier to just
put the entire path inside the call. This prevents possible
double-bashslashes if the constant already expands to include a trailing
backslash.

Gerard Joseph

unread,
Aug 7, 2020, 3:12:20 PM8/7/20
to innosetup
hello Gavin

I am new to inno setup but was wondering if you could help me out with how to check if the application is already installed...and if so, prompt to uninstall it.

like how would I do this in my setup script i have?

regards,

Gerard

Gavin Lambert

unread,
Aug 9, 2020, 6:59:23 PM8/9/20
to inno...@googlegroups.com
On 8/08/2020 07:12, Gerard Joseph wrote:
> I am new to inno setup but was wondering if you could help me out with
> how to check if the application is already installed...and if so, prompt
> to uninstall it.

Assuming that the prior install was also made with Inno, then there's no
need to do this -- just install over the top; by default the uninstall
information for the second run will be appended to the first.

If there are some redundant files from an old version that you want to
delete in the new version you can use [InstallDelete], but that's rarely
necessary.

The main thing is just that any files in {app} should usually have
Flags: ignoreversion.


If your prior install was made with some other install tool, especially
something MSI-based, then you will need to uninstall it before
installing the Inno-based version. That's just a matter of locating the
uninstall entry in the registry and then running it during PrepareToInstall.
Reply all
Reply to author
Forward
0 new messages