Search code examples
inno-setupuninstallationregistrykey

Inno Setup : Create Uninstall Registry Key only when needed


I need to force the directive CreateUninstallRegKey in the [Setup] Section to only create the Registry Key for uninstall when needed.

For example , if I set a condition to create Uninstall Registry Key, it must only be created when the condition goes True. Otherwise the Uninstall Registry Key must not be created.

How can I do this in Inno Setup?

UPDATED QUESTION

The code I wrote is:

[Setup]
CreateUninstallRegKey=RegKeyDeterminer

[Code]
function RegKeyDeterminer(): Boolean;
  begin
  Result:= ISDoneError = True;
  if ISDoneError = True then Result:= True;
end;

With this code , The Uninstall Registry Key is always creating. (It should be something wrong in the code I wrote.)

The Uninstall Registry Key must not be created if ISDoneError = True.

The Uninstall Registry Key must be created if ISDoneError = False.

ISDoneError only has True or False values.(It is a Boolean Function in ISDone.dll which is a Dynamic Link Library that used to extract files from 7-Zip,RAR,Binary etc. archives in Inno Setup.)

These are the conditions. If you can see any mistakes or condition setting errors , then correct my code.

Thank You.


Solution

  • The CreateUninstallRegKey directive can take a boolean expression/function as its value.

    So just implement the function to return True when you need to create the key and False otherwise.

     [Setup]
     CreateUninstallRegKey=CreateKey
    
     [Code]
    
     function CreateKey: Boolean;
     begin
       Result := condition;
     end;