Uninstall when starting inno setup with an application already installed

I just started using inno setup and it seems to work fine. However, when I run the installer with the application already installed, it reinstalls. I would like to give the user a delete. Is this possible, and if so, how can this be done?

To be specific, I wrote a game for homework. I did the installer using intro setup. The application installs perfectly and can be removed using the control panel, but my professor would like to uninstall the application by restarting the installation program and choosing the uninstall option. This will save him time, as he has about 50 of these tasks.

Thanks,

Gerry

+7
source share
3 answers

The following script will create the following parameters when the application is already installed on the target system when the installation starts:

enter image description here

When the user clicks the Repair button, the setup usually starts. When the user clicks the Uninstall button, the previously installed application is deleted. When a user closes this form, nothing happens.

Here is the script (do not forget to indicate, ideally, some unique value for the AppId configuration directive in your script):

 [Setup] AppName=My Program AppVersion=1.5 AppId=1C9FAC66-219F-445B-8863-20DEAF8BB5CC DefaultDirName={pf}\My Program OutputDir=userdocs:Inno Setup Examples Output [CustomMessages] OptionsFormCaption=Setup options... RepairButtonCaption=Repair UninstallButtonCaption=Uninstall [Code] const mrRepair = 100; mrUninstall = 101; function ShowOptionsForm: TModalResult; var OptionsForm: TSetupForm; RepairButton: TNewButton; UninstallButton: TNewButton; begin Result := mrNone; OptionsForm := CreateCustomForm; try OptionsForm.Width := 220; OptionsForm.Caption := ExpandConstant('{cm:OptionsFormCaption}'); OptionsForm.Position := poScreenCenter; RepairButton := TNewButton.Create(OptionsForm); RepairButton.Parent := OptionsForm; RepairButton.Left := 8; RepairButton.Top := 8; RepairButton.Width := OptionsForm.ClientWidth - 16; RepairButton.Caption := ExpandConstant('{cm:RepairButtonCaption}'); RepairButton.ModalResult := mrRepair; UninstallButton := TNewButton.Create(OptionsForm); UninstallButton.Parent := OptionsForm; UninstallButton.Left := 8; UninstallButton.Top := RepairButton.Top + RepairButton.Height + 8; UninstallButton.Width := OptionsForm.ClientWidth - 16; UninstallButton.Caption := ExpandConstant('{cm:UninstallButtonCaption}'); UninstallButton.ModalResult := mrUninstall; OptionsForm.ClientHeight := RepairButton.Height + UninstallButton.Height + 24; Result := OptionsForm.ShowModal; finally OptionsForm.Free; end; end; function GetUninstallerPath: string; var RegKey: string; begin Result := ''; RegKey := Format('%s\%s_is1', ['Software\Microsoft\Windows\CurrentVersion\Uninstall', '{#emit SetupSetting("AppId")}']); if not RegQueryStringValue(HKEY_LOCAL_MACHINE, RegKey, 'UninstallString', Result) then RegQueryStringValue(HKEY_CURRENT_USER, RegKey, 'UninstallString', Result); end; function InitializeSetup: Boolean; var UninstPath: string; ResultCode: Integer; begin Result := True; UninstPath := RemoveQuotes(GetUninstallerPath); if UninstPath <> '' then begin case ShowOptionsForm of mrRepair: Result := True; mrUninstall: begin Result := False; if not Exec(UninstPath, '', '', SW_SHOW, ewNoWait, ResultCode) then MsgBox(FmtMessage(SetupMessage(msgUninstallOpenError), [UninstPath]), mbError, MB_OK); end; else Result := False; end; end; end; 
+11
source

For some reason your code

 RegKey := Format('%s\%s_is1', ['Software\Microsoft\Windows\CurrentVersion\Uninstall', '{#emit SetupSetting("AppId")}']); 

returned extra {to the value of _is1. I did not have time to check why or where I was mistaken in my implementation, all I confirm is that my installer works with

 RegKey := ExpandConstant('Software\Microsoft\Windows\CurrentVersion\Uninstall\{#emit SetupSetting("AppId")}_is1'); 

alternate.

Hope this helps.

Thanks for the sample code.

+2
source

When using Inno Setup, there is no reason to uninstall the previous version if this version was not installed by another installer. Otherwise, the update is performed automatically.

Your answer is here:

InnoSetup: how to automatically uninstall the previous installed version? previous installed version

+1
source

All Articles