Changing uninstall confirmation prompt

2019-01-15 11:07发布

问题:

Is it possible to use code to change the messages in the [Messages] section? I want to change the message ConfirmUninstall as shown below.

[Messages]
ConfirmUninstall=Are you sure you want to remove {code:GetIDandName} and its components.

Is it possible to do something like this? If not, is there a way that this could be achieved?

Thank You.

回答1:

No you cannot.

In some cases you might be able to use a preprocessor.

But not in your situation.

You may automate the UI, but it's not nice. See Inno Setup - Automatically submitting uninstall prompts.


All you can do with ConfirmUninstall is:

  • suppress it by forcing the /SILENT switch in an Add/Remove programs entry (add another custom switch to make it clear that it's actually not the silent mode) and
  • implement your own prompt in the InitializeUninstall event function.
[Setup]
AppId=myprogram

[Code]

const
  UninstallKey =
    'SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{#SetupSetting("AppId")}_is1';
  UninstallStringName = 'UninstallString';
  CustomUninstallPromptSwitch = '/CUSTOMUNINSTALLPROMPT';
  UninstallSwitches = '/SILENT ' + CustomUninstallPromptSwitch;

procedure CurStepChanged(CurStep: TSetupStep);
var
  S: string;
begin
  if CurStep = ssPostInstall then
  begin
    if not RegQueryStringValue(
             HKEY_LOCAL_MACHINE, ExpandConstant(UninstallKey),
             UninstallStringName, S) then
    begin
      Log(Format(
           'Cannot find %s in %s', [
           UninstallStringName, ExpandConstant(UninstallKey)]));
    end
      else
    begin
      Log(Format('%s is %s', [UninstallStringName, S]));
      S := S + ' ' + UninstallSwitches;
      if not RegWriteStringValue(
               HKEY_LOCAL_MACHINE, ExpandConstant(UninstallKey), 
               UninstallStringName, S) then
      begin
        Log(Format('Error writting %s', [UninstallStringName]));
      end
        else
      begin
        Log(Format('Written [%s] to %s', [S, UninstallStringName]));
      end;
    end;
  end;
end;

function CmdLineParamExists(const Value: string): Boolean;
var
  I: Integer;
begin
  Result := False;
  for I := 1 to ParamCount do
  begin
    if CompareText(ParamStr(I), Value) = 0 then
    begin
      Result := True;
      Exit;
    end;
  end;
end;

function GetIDandName: string;
begin
  Result := ...;
end;

function InitializeUninstall(): Boolean;
var
  Text: string;
begin
  Result := True;

  if CmdLineParamExists(CustomUninstallPromptSwitch) and UninstallSilent then
  begin
    Log('Custom uninstall prompt');
    Text := FmtMessage(SetupMessage(msgConfirmUninstall), [GetIDandName()]);
    Result := (MsgBox(Text, mbConfirmation, MB_YESNO) = IDYES);
  end;
end;

You can even go a step further and disallow the uninstaller to proceed, when not executed with the custom switch. This way you prevent the user from launching the unins000.exe from the installation folder manually.

function InitializeUninstall(): Boolean;
var
  Text: string;
begin
  Result := True;

  if not CmdLineParamExists(CustomUninstallPromptSwitch) then
  begin
    MsgBox('Please go to Control Panel/Settings to uninstall this program.',
           mbError, MB_OK);
    Result := False;
  end
    else
  if UninstallSilent then
  begin
    Log('Custom uninstall prompt');
    Text := FmtMessage(SetupMessage(msgConfirmUninstall), [GetIDandName()]);
    Result := (MsgBox(Text, mbConfirmation, MB_YESNO) = IDYES);
  end;
end;


标签: inno-setup