记得以前看过一篇文章,文章说windows关机前要关闭应用程序,只要让你的应用程序不会关闭就行了,另外我想关机时会向系统发送一条消息,用WH_GETMESSAGE
hook截获该消息就行了

解决方案 »

  1.   

    在关闭系统时,Windows向所有程序发送WM_QUERYENDSESSION 和 WM_ENDSESSION消息,并等待返回TRUE;ExitWindowsEx(EXW_FORCE, 0);
    系统不向任何程序发WM_QUERYENDSESSION 和 WM_ENDSESSION消息
    会导致丢失信息。根据M$的说法这是不可抗拒的,只用于紧急情况。
    不信你按键盘上的Power键试试
      

  2.   

    ExitWindowsEx(EXW_FORCE,  0)
    不管用呀,屏幕一闪就恢复了
      

  3.   

    kao,这还用我编吗,你的方法效率太低了,用机器人不如用我呢
      

  4.   

    ExitWindowsEx(EXW_FORCE|EWX_POWEROFF,    0)
      

  5.   

    EWX_FORCE Forces processes to terminate. When this flag is set, Windows does not send the messages WM_QUERYENDSESSION and WM_ENDSESSION to the applications currently running in the system. This can cause the applications to lose data. Therefore, you should only use this flag in an emergency.
    EWX_LOGOFF Shuts down all processes running in the security context of the process that called the ExitWindowsEx function. Then it logs the user off.
    EWX_POWEROFF Shuts down the system and turns off the power. The system must support the power-off feature.Windows NT: The calling process must have the SE_SHUTDOWN_NAME privilege. For more information, see the following Res section. Windows 95: Security privileges are not supported or required.
    EWX_REBOOT Shuts down the system and then restarts the system. Windows NT: The calling process must have the SE_SHUTDOWN_NAME privilege. For more information, see the following Res section. Windows 95: Security privileges are not supported or required.
    EWX_SHUTDOWN
      

  6.   

    PROCEDURE TA_PW.SHUTDOWN(INFO:STRING);
    const
      SE_SHUTDOWN_NAME = 'SeShutdownPrivilege';
      hToken       : THandle;
      tkp          : TTokenPrivileges;
      tkpo         : TTokenPrivileges;
      zero         : DWORD;
    begin
      if INFO = 'Windows NT'  then
         begin
            zero := 0;
            if not OpenProcessToken( GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES or TOKEN_QUERY, hToken) then
               begin
                 MessageBox( 0, 'Exit Error', 'OpenProcessToken() Failed', MB_OK );
                 Exit;
               end;
            if not LookupPrivilegeValue( nil, 'SeShutdownPrivilege' , tkp.Privileges[ 0 ].Luid ) then
               begin
                  MessageBox( 0, 'Exit Error', 'LookupPrivilegeValue() Failed', MB_OK );
                  Exit;
               end;
            tkp.PrivilegeCount := 1;
            tkp.Privileges[ 0 ].Attributes := SE_PRIVILEGE_ENABLED;        AdjustTokenPrivileges( hToken, False, tkp, SizeOf( TTokenPrivileges ), tkpo, zero );
            if Boolean( GetLastError() ) then
               begin
                  MessageBox( 0, 'Exit Error', 'AdjustTokenPrivileges() Failed', MB_OK );
                  Exit;
               end
            else
               ExitWindowsEx( EWX_SHUTDOWN or EWX_POWEROFF, 0 );
          end
       else
          begin
            ExitWindowsEx( EWX_SHUTDOWN or EWX_POWEROFF, 0 );
            ExitWindowsEx( EWX_FORCE or EWX_SHUTDOWN, 0 );
          end;
    end;参数 info 为系统类型,在W2K,WIN9X,可执行关机,W2K需有关机权限
      

  7.   

    ExitWindows在Delphi的调试环境中好像是没有用的。
      

  8.   

    是啊,ExitWindows用9x下还可以。可是在2000下就不灵了。如关机的关不了。
    不知要用什么办法?
      

  9.   

    只有rwdx(任我独行) 的方法行