How do I structure my Inno Setup script to automatically register a dll if it is the first time a user has installed my application but unregister a previous version if there is one and then register the new one (assuming the interface is different)?
I currently use the the regserver and ignoreversion flags in my Files section as seen below:
[Setup]
...
[Languages]
...
[Files]
Source: "C:\example.dll"; DestDir: "{app}"; Flags: ignoreversion regserver
In my google search I have found UnregisterServer but I not know how to add this to my script. I would gladly start tinkering around to see how this works, but I do not want to do anything that will mess-up my registry.
There is a similar post here but it does not address how this is actually accomplished.
EDIT
After hacking around in Pascal I was able to add the following to the [Code] section and it worked. Does anyone know how to use the {app} constant to dynamically define the fileName in the code below?
[Code]
const
fileName = 'C:\Program Files\TFolderName\tigercontroller.dll';
var
serverExists: Boolean;
function InitializeSetup(): Boolean;
begin
serverExists := UnregisterServer(False, fileName, False);
if serverExists then begin
Result:= True;
MsgBox('This will update with the most recent version', mbInformation, mb_Ok);
end else
Result := True;
end;
{app}constant at theInitializeSetuptime. Moreover, the{app}constant contains the currently selected install folder whilst you want to check the previous application folder. You can get the last folder fromWizardForm.PrevAppDirproperty soonest from theInitializeWizardevent method e.g.this way. - TLamaWizardForm.PrevAppDiris just a property holding the folder path, where the installer with a certainAppIdhas previously installed the application (empty if not yet installed). In other words, this property will return you the previous install folder path unless you change theAppIdin your script. Once you changeAppId, it is treated as a different setup. - TLama