Vinoth
Vinoth

Reputation: 1995

Uninstall the Add-on setup before uninstall the main setup using Inno setup

My requirement is below; I have read the Add-on Product Id from registry and uninstall the setup using that product ID before uninstall the Main setup. I have used the below code

[code]
const
  RegProductLocation = 'SOFTWARE\My Company\My Product\Sample\ {#Version}';
var SamplesProductId : string;
function GetSamplesID(): Boolean;
begin
  if RegQueryStringValue(HKEY_CURRENT_USER, RegProductLocation, 'ProductID', SamplesProductId) then
begin
    Result:= true;
end else begin
Result:= false;   
  end;end;

[UninstallRun] 
Filename: msiexec.exe; Parameters: " /x ""{SamplesProductId}"" /qn"; Check:GetSamplesID();  Flags: runhidden;

It is not compiled by Inno setup and shows error. Could you please help me to solve this issue?

Upvotes: 1

Views: 1362

Answers (1)

Deanna
Deanna

Reputation: 24253

You need to use a function and a {code:...} constant to access data from [Code]

Something like this (untested air code):

[UninstallRun] 
Filename: msiexec.exe; Parameters: "/x ""{code:GetSamplesID}"" /qn"; Check:CheckHasSamplesID(); Flags: runhidden; 

[code]
const
  RegProductLocation = 'SOFTWARE\My Company\My Product\Sample\{#Version}';
var
  SamplesProductId : string;

function CheckHasSamplesID(): Boolean;
begin
  if RegQueryStringValue(HKEY_CURRENT_USER, RegProductLocation, 'ProductID', SamplesProductId) then begin
    Result:= true;
  end else begin
    Result:= false;   
  end;
end;

function GetSamplesID(Param: String): String;
begin
  Result:= SamplesProductId;
end;

Note there was an extrenuous space in your RegProductLocation constant.

Upvotes: 1

Related Questions