更改卸载确认提示

问题描述 投票:0回答:1

是否可以使用代码来更改

[Messages]
部分中的消息? 我想更改消息
ConfirmUninstall
,如下所示。

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

可以做这样的事情吗?如果没有的话有什么方法可以实现吗?

谢谢你。

inno-setup
1个回答
5
投票

不,你不能。

在某些情况下,您可能可以使用预处理器

但不是你的情况。

您可以自动化 UI,但这并不好。
请参阅自动提交 Inno Setup 卸载提示


您可以使用

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;
© www.soinside.com 2019 - 2024. All rights reserved.