我在程序中处理了WM_QUERYENDSESSION  WM_ENDSESSION
系统在重启时间程序成功
但系统选择关机时就不行
请问是什么原因

解决方案 »

  1.   

    试一试这个吧,我没有win98,试不了,不过应该可以的!
    我在窗体中加入一个复选框(CHECKBOX),如果不选中它,则无法关闭WIN9X,如果选中它,才可以关闭。你可以改成自己的需要处理方式试试!
    unit Unit1;        interface        uses Windows, Messages, SysUtils,Classes, Graphics, Controls, Forms, Dialogs, StdCtrls;        type
              TForm1 = class(TForm)
                  CheckBox1: TCheckBox;
              private
                { Private declarations }
               //声明拦截WM_QueryEndSession消息的过程    
                 procedure WMQueryEndSession(var Msg: TMessage); message WM_QueryEndSession;
              public
                { Public declarations }
              end;        var
              Form1: TForm1;        implementation
            {$R *.DFM}        procedure TForm1.WMQueryEndSession(var Msg: TMessage);
            begin
              if CheckBox1.Checked then 
                    Msg.Result := 1
              else 
                    Msg.Result := 0;
           end;
           end.
      

  2.   

    //--重启动
          if Win32Platform <> VER_PLATFORM_WIN32_NT then //不是NT
            ExitWindowsEx(EWX_REBOOT, 0)
          else
          begin
               SetPrivilege('SeShutdownPrivilege', True);
                 if not ExitWindowsEx(EWX_REBOOT + EWX_FORCE, 0) then
                   SetPrivilege('SeShutdownPrivilege', False);
          end;    //--关机
          if Win32Platform <> VER_PLATFORM_WIN32_NT then //不是NT
            ShellExecute(handle, 'open', 'RUNDLL32.EXE', 'user.exe,ExitWindows', nil, SW_ShowNormal)
          else
          begin
               SetPrivilege('SeShutdownPrivilege', True);
                 if not ExitWindowsEx(EWX_SHUTDOWN + EWX_FORCE+EWX_POWEROFF, 0) then
                   SetPrivilege('SeShutdownPrivilege', False);
          end;
      

  3.   

    在WINDOWS98关机时,会给没一个应用程序发送WM_QUERYENDSESSION消息,你只要在你的程序中处理该消息,就可以控制是否关机。也就是说:如果你让该消息的RESULT为0的话,那么WINDOWS98是不会执行关机的。