更改卸载确认提示 [英] Changing uninstall confirmation prompt

查看:198
本文介绍了更改卸载确认提示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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?

谢谢.

推荐答案

不,你不能.

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

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

但您的情况并非如此.

您可以自动执行UI,但这并不好.请参阅 Inno设置-自动提交卸载提示.

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

ConfirmUninstall所能做的就是:

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


如果不使用自定义开关执行卸载,则甚至可以更进一步,并禁止卸载程序继续运行.这样,可以防止用户手动从安装文件夹中启动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;

这篇关于更改卸载确认提示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆