Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
572 views
in Technique[技术] by (71.8m points)

inno setup - Changing uninstall confirmation prompt

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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:

[Setup]
AppId=myprogram

[Code]

const
  UninstallKey =
    'SOFTWAREMicrosoftWindowsCurrentVersionUninstall' +
      '{#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;

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...