更改卸载确认提示

时间:2015-12-07 04:59:49

标签: inno-setup

是否可以使用代码更改[Messages]部分中的消息? 我想更改消息ConfirmUninstall,如下所示。

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

有可能做这样的事吗?如果没有,有没有办法实现这一目标?

谢谢。

1 个答案:

答案 0 :(得分:3)

不,你不能。

在某些情况下,您可以使用a preprocessor

但不是在你的情况下。

您可以自动化UI,但这并不好。请参阅Inno Setup - Automatically submitting uninstall prompts

您使用ConfirmUninstall所能做的就是:

[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;

当您没有使用自定义开关执行时,您甚至可以更进一步禁止卸载程序继续运行。这样可以防止用户手动从安装文件夹中启动unins000.exe

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;
相关问题