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;
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…