![](/uploads/1/2/7/6/127646696/856478441.jpg)
How to detect old installation and offer removal? Ask Question. How do I detect whether the user already installed the software and if so, how to offer the possibility of removing the old version? I have written some lines to check that. @Deanna For my customer it is true that this software will always be installed with an inno setup.
You could use something like FindWindowByWindowName and then issue a SendMessage with a WMQUIT to close the application (or just abort the install after displaying a message. Something like:function InitializeSetup: Boolean; const WMQUIT = 18; var winHwnd: longint; retVal: boolean; strProg: string; begin result:=true; try strProg:= 'MyApplication.exe'; winHwnd:= FindWindowByWindowName(strProg); if winHwnd 0 then begin //retVal:=postmessage(winHwnd,WMQUIT,0,0); //or //Display Message Box saying application is running // and close it, then exit setup by setting: //result:=false; except end; end;Select all.
![Inno setup update existing installation Inno setup update existing installation](/uploads/1/2/7/6/127646696/269460083.jpg)
[InnoSetup] Prevent install if newer version is already installed
check-version.iss
#define AppId '{INSERT HERE YOUR GUID}' |
#define AppName 'My App' |
#define AppVersion '1.7' |
[CustomMessages] |
english.NewerVersionExists=A newer version of {#AppName} is already installed.%n%nInstaller version: {#AppVersion}%nCurrent version: |
[Code] |
// find current version before installation |
functionInitializeSetup: Boolean; |
var Version: String; |
begin |
if RegValueExists(HKEY_LOCAL_MACHINE,'SoftwareMicrosoftWindowsCurrentVersionUninstall{#AppId}_is1', 'DisplayVersion') then |
begin |
RegQueryStringValue(HKEY_LOCAL_MACHINE,'SoftwareMicrosoftWindowsCurrentVersionUninstall{#AppId}_is1', 'DisplayVersion', Version); |
if Version > '{#AppVersion}'then |
begin |
MsgBox(ExpandConstant('{cm:NewerVersionExists} '+Version), mbInformation, MB_OK); |
Result := False; |
end |
else |
begin |
Result := True; |
end |
end |
else |
begin |
Result := True; |
end |
end; |
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment
![](/uploads/1/2/7/6/127646696/856478441.jpg)