Inno Setup明确拒绝WM_QUERYENDSESSION
消息。如果不修改Inno Setup源代码,您无法做任何事情。
见TDummyClass.AntiShutdownHook
method:
class function TDummyClass.AntiShutdownHook(var Message: TMessage): Boolean;
begin
{ This causes Setup/Uninstall/RegSvr to all deny shutdown attempts.
- If we were to return 1, Windows will send us a WM_ENDSESSION message and
TApplication.WndProc will call Halt in response. This is no good because
it would cause an unclean shutdown of Setup, and it would also prevent
the right exit code from being returned.
Even if TApplication.WndProc didn't call Halt, it is my understanding
that Windows could kill us off after sending us the WM_ENDSESSION message
(see the Remarks section of the WM_ENDSESSION docs).
- SetupLdr denys shutdown attempts as well, so there is little point in
Setup trying to handle them. (Depending on the version of Windows, we
may never even get a WM_QUERYENDSESSION message because of that.)
Note: TSetupForm also has a WM_QUERYENDSESSION handler of its own to
prevent CloseQuery from being called. }
Result := False;
case Message.Msg of
WM_QUERYENDSESSION: begin
{ Return zero, except if RestartInitiatedByThisProcess is set
(which means we called RestartComputer previously) }
if RestartInitiatedByThisProcess or (IsUninstaller and AllowUninstallerShutdown) then begin
AcceptedQueryEndSessionInProgress := True;
Message.Result := 1
end else
Message.Result := 0;
Result := True;
end;
{ ... }
和TSetupForm.WMQueryEndSession
method:
procedure TSetupForm.WMQueryEndSession(var Message: TWMQueryEndSession);
begin
{ TDummyClass.AntiShutdownHook in Setup.dpr already denies shutdown attempts
but we also need to catch WM_QUERYENDSESSION here to suppress the VCL's
default handling which calls CloseQuery. We do not want to let TMainForm &
TNewDiskForm display any 'Exit Setup?' message boxes since we're already
denying shutdown attempts, and also we can't allow them to potentially be
displayed on top of another dialog box that's already displayed. }
{ Return zero, except if RestartInitiatedByThisProcess is set (which means
we called RestartComputer previously) }
if RestartInitiatedByThisProcess then
Message.Result := 1;
end;
感谢马丁。遗憾的是,不修改源代码是不可能的。 –