Forced uninstall of previous version before run install

1,032 views
Skip to first unread message

Majkl

unread,
Jul 18, 2022, 3:42:05 PM7/18/22
to innosetup
I need user to unistall previous version before instal the new one.
Could I force it in isntall program?

Laurent Combémorel

unread,
Jul 19, 2022, 3:49:22 AM7/19/22
to innosetup
yes

Lee Cley da Silva Lima

unread,
Jul 19, 2022, 9:49:30 AM7/19/22
to innosetup
add this code to your script it will always delete the previous version during installation and leave only the new one!


{ ///////////////////////////////////////////////////////////////////// }
function GetUninstallString(): String;
var
  sUnInstPath: String;
  sUnInstallString: String;
begin
  sUnInstPath := ExpandConstant('Software\Microsoft\Windows\CurrentVersion\Uninstall\{#emit SetupSetting("AppId")}_is1');
  sUnInstallString := '';
  if not RegQueryStringValue(HKLM, sUnInstPath, 'UninstallString', sUnInstallString) then
    RegQueryStringValue(HKCU, sUnInstPath, 'UninstallString', sUnInstallString);
  Result := sUnInstallString;
end;


{ ///////////////////////////////////////////////////////////////////// }
function IsUpgrade(): Boolean;
begin
  Result := (GetUninstallString() <> '');
end;


{ ///////////////////////////////////////////////////////////////////// }
function UnInstallOldVersion(): Integer;
var
  sUnInstallString: String;
  iResultCode: Integer;
begin
{ Return Values: }
{ 1 - uninstall string is empty }
{ 2 - error executing the UnInstallString }
{ 3 - successfully executed the UnInstallString }

  { default return value }
  Result := 0;

  { get the uninstall string of the old app }
  sUnInstallString := GetUninstallString();
  if sUnInstallString <> '' then begin
    sUnInstallString := RemoveQuotes(sUnInstallString);
    if Exec(sUnInstallString, '/SILENT /NORESTART /SUPPRESSMSGBOXES','', SW_HIDE, ewWaitUntilTerminated, iResultCode) then
      Result := 3
    else
      Result := 2;
  end else
    Result := 1;
end;
end;

sanil john

unread,
Jul 20, 2022, 4:39:01 AM7/20/22
to inno...@googlegroups.com
Thank you Lee. New exe is creating now.

I am facing another issue ,my vb6.0 project is not loading now. It shows lots of files missing after creating the setup using Inno.

Regards,
Sanil John

--
You received this message because you are subscribed to the Google Groups "innosetup" group.
To unsubscribe from this group and stop receiving emails from it, send an email to innosetup+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/innosetup/36fb25d5-0829-4e6b-b28f-b58da29ae5e5n%40googlegroups.com.


--
Sanil John

Bill Stewart

unread,
Jul 21, 2022, 12:30:55 PM7/21/22
to innosetup
On Wednesday, July 20, 2022 at 2:39:01 AM UTC-6 sanil john wrote:

I am facing another issue ,my vb6.0 project is not loading now. It shows lots of files missing after creating the setup using Inno.

This is not a problem in Inno Setup itself but rather in what specifically you are telling Inno Setup to do to install your program.

There is generally speaking no way we can tell you how to fix that because we don't have your application or its requirements and dependencies.

My recommendation is that you need to document all of the requirements and dependencies to get your application installed on a target system. The requirements and dependencies will, naturally, depend on your application.

Only after you have specifically documented all of the necessary requirements and dependencies will you be able to write an installer script that creates a usable application on a target system.

Guessing about the requirements and dependencies isn't going to work.

Bill

Alessandro Marinuzzi

unread,
Jul 21, 2022, 1:29:16 PM7/21/22
to innosetup
Please, try this:

Change YourApp with your one.

[Code]
procedure CurStepChanged(CurStep: TSetupStep);
var
  ResultCode: Integer;
  Uninstall: String;
begin
  if (CurStep = ssInstall) then begin
    if RegQueryStringValue(HKLM, 'SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\YourApp_is1', 'UninstallString', Uninstall) then begin
      MsgBox('Warning: an old version of YourApp is installed! Now the old one will be removed and installed the new!', mbInformation, MB_OK);
      Exec(RemoveQuotes(Uninstall), ' /SILENT', '', SW_SHOWNORMAL, ewWaitUntilTerminated, ResultCode);
    end;
  end;
end;
Reply all
Reply to author
Forward
0 new messages