Changing uninstall confirmation prompt

前端 未结 1 1721
自闭症患者
自闭症患者 2020-12-06 15:37

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

相关标签:
1条回答
  • 2020-12-06 16:16

    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;
    
    0 讨论(0)
提交回复
热议问题