inno setup for updates code example
Example: inno setup make setup and update
#define MyAppVersion "1.2.2.7570"
#define MyAppName "MyApp Update"
[Setup]
AppId=MyApp
AppName={#MyAppName}
AppVersion={#MyAppVersion}
DefaultDirName={reg:HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\MyApp_is1,InstallLocation}
DisableDirPage=True
[CustomMessages]
MyAppOld=The Setup detected application version
MyAppRequired=The installation of {#MyAppName} requires MyApp to be installed.%nInstall MyApp before installing this update.%n%n
MyAppTerminated=The setup of update will be terminated.
[Code]
var
InstallLocation: String;
function GetInstallString(): String;
var
InstPath: String;
InstallString: String;
begin
InstPath := ExpandConstant('Software\Microsoft\Windows\CurrentVersion\Uninstall\MyApp_is1');
InstallString := '';
if not RegQueryStringValue(HKLM, InstPath, 'InstallLocation', InstallString) then
RegQueryStringValue(HKCU, InstPath, 'InstallLocation', InstallString);
Result := InstallString;
InstallLocation := InstallString;
end;
function InitializeSetup: Boolean;
var
V: Integer;
sUnInstallString: String;
Version: String;
begin
if RegValueExists(HKEY_LOCAL_MACHINE,'Software\Microsoft\Windows\CurrentVersion\Uninstall\MyApp_is1', 'UninstallString') then begin
RegQueryStringValue(HKEY_LOCAL_MACHINE,'Software\Microsoft\Windows\CurrentVersion\Uninstall\MyApp_is1', 'DisplayVersion', Version);
if Version =< ExpandConstant('{#MyAppVersion}') then begin
Result := True;
GetInstallString();
end
else begin
MsgBox(ExpandConstant('{cm:MyAppOld}'+Version+'.'+#13#10#13#10+'{cm:MyAppRequired}'+'{cm:MyAppTerminated}'), mbInformation, MB_OK);
Result := False;
end;
end
else begin
MsgBox(ExpandConstant('{cm:MyAppRequired}'+'{cm:MyAppTerminated}'), mbInformation, MB_OK);
Result := False;
end;
end;