I am trying to configure Inno setup for my software (this is a C# software). I plan to release many versions of my software, I would like to change the Inno setup installer interface if an older version of my application is already installed on the computer. In this case, the user shouldn't be able to change the install directory.
There are four cases:
First case: this is the first installation of my product, Inno setup should proceed normally.
Second case: the product is already installed AND the installer contains a newer version. The user cannot choose the destination folder. He can just run the update.
Third case: If the installer contains an older version than the installed one, the update will be disabled and a message should be displayed.
Fourth case: The installer version is the same than the installed version. The user can repair his actual version if needed.
Is it possible to do that with InnoSetup?
Inno Setup already handles cases 1, 2, and 4 automatically if your AppID
is kept the same for the life of the application.
You can also hide the directory and group pages using the following[Setup]
directives:
DisableDirPage=auto
DisableGroupPage=auto
See this ISXKB article for more details.
For case 3, assuming your files are versioned correctly, Inno won't downgrade anything, but it won't actually warn the user. To do that, you will need to add code to check this, most likely in the InitializeSetup()
event function.
If you want to have some feedback for user you can try something like that.
First of all, your update should have the same AppId
name as your Main App.
Then you can set some checks, that will display messages to inform user about the state.
#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;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With