Preventing Windows shut down

前端 未结 7 568
梦毁少年i
梦毁少年i 2021-01-18 09:14

To detect and prevent shutdown the computer I use very simple program. It has only one form and one private procedure like below:

TForm3 = class(TForm)
priva         


        
相关标签:
7条回答
  • 2021-01-18 09:30

    This looks like a bug in Delphi. I suggest you to post this on Quality Central.

    0 讨论(0)
  • 2021-01-18 09:34

    I usually run "shutdown -a" command. You can do the same from your code to interrupt Windows from shutdown.

    Regards

    0 讨论(0)
  • 2021-01-18 09:34

    In all versions should you not be using the FormCloseQuery event?

    procedure TForm3.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
    begin
      Canclose := Not StillDoingImportantStuff;
    end;
    

    Oops - just read comments to "this does not work" :( Is win 7 different?

    In all my apps this gets called if windows is trying to shut down...

    0 讨论(0)
  • 2021-01-18 09:42

    ShutdownGuard is built with Delphi and it's open source, you can download it tweak it for your needs

    0 讨论(0)
  • 2021-01-18 09:49

    EDIT: changed to intercept WM_ENDSESSION instead of WM_QUERYENDSESSION.

    As you cannot directly change the behaviour of TApplication, you can install a TApplication message hook instead that neutralizes the WM_ENDSESSION message.

    Installing such a hook is quite simple, you only have to add a method similar to the following to your mainform and register the hook in FormCreate.

    function TForm25.HookEndSession(var Message: TMessage): Boolean;
    begin
      result := false;
      if Message.Msg = WM_ENDSESSION then begin
        Message.Result := 0;
        result := true;
      end;
    end;
    
    procedure TForm25.FormCreate(Sender: TObject);
    begin
      Application.HookMainWindow(HookEndSession);
    end;
    
    0 讨论(0)
  • 2021-01-18 09:50

    Are you testing on the same OS? There are some application shutdown changes in Vista. Read this: Application Shutdown Changes in Windows Vista

    If you are testing on the same OS, maybe Delphi 2010 handles WM_ENDSESSION messages in a different way. In Delphi 7, WM_ENDSESSION message are handled in Application.WndProc.

    0 讨论(0)
提交回复
热议问题