The ExitWindowsEx function either logs off, shuts down, or shuts down and restarts the system. BOOL ExitWindowsEx(    UINT uFlags, // shutdown operation
    DWORD dwReserved  // reserved
   );
 ParametersuFlagsSpecifies the type of shutdown. This parameter must be some combination of the following values: Value Meaning
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 Shuts down the system to a point at which it is safe to turn off the power. All file buffers have been flushed to disk, and all running processes have stopped. 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.
 dwReservedReserved; this parameter is ignored.  Return ValuesIf the function succeeds, the return value is nonzero.
If the function fails, the return value is zero. To get extended error information, call GetLastError. ResThe ExitWindowsEx function returns as soon as it has initiated the shutdown. The shutdown or logoff then proceeds asynchronously. 
During a shutdown or log-off operation, applications that are shut down are allowed a specific amount of time to respond to the shutdown request. If the time expires, Windows displays a dialog box that allows the user to forcibly shut down the application, to retry the shutdown, or to cancel the shutdown request. If the EWX_FORCE value is specified, Windows always forces applications to close and does not display the dialog box. The ExitWindowsEx function sends a separate notification message, CTRL_SHUTDOWN_EVENT or CTRL_LOGOFF_EVENT as the situation warrants, to console processes. A console process routes these messages to its HandlerRoutine functions, which are added and removed by calls to the SetConsoleCtrlHandler function. ExitWindowsEx sends these notification messages asynchronously; thus, an application cannot assume that the console notification messages have been handled when a call to ExitWindowsEx returns. Windows NT: To shut down or restart the system, the calling process must use the AdjustTokenPrivileges function to enable the SE_SHUTDOWN_NAME privilege. For more information about security privileges, see Privileges. 
Windows 95: Security privileges are not supported or required.

解决方案 »

  1.   

    这个我在Delphi5的帮助文档里也看到了。只是看不懂。有没有具体实例之类的东东呀?比如说一个最简单的,在FORM中有一个关机BUTTON,单击就实现系统关机。
      

  2.   

    procedure TForm1.Button1Click(Sender: TObject);
    begin
             ExitWindowsEx(EWX_REBOOT,0);
    end;
    这样能行么?第二个参数是用来干什么的呀?
      

  3.   

    列举当前系统运行进程
    uses TLHelp32;
    procedure TForm1.Button1Click(Sender: TObject);
    var lppe: TProcessEntry32;
    found : boolean;
    Hand : THandle;
    begin
    Hand := CreateToolhelp32Snapshot(TH32CS_SNAPALL,0);
    found := Process32First(Hand,lppe);
    while found do
    begin
    ListBox1.Items.Add(StrPas(lppe.szExeFile));
    found := Process32Next(Hand,lppe);
    end;
    end;
      

  4.   

    dwReservedReserved; this parameter is ignored这里不是说这个参数可以省?为什么我不要这个参数DELPHI会提示参数不全?
      

  5.   

    DWORD dwReserved  // reserved的中文意思就是:保留!设为零!!
      

  6.   

    procedure TForm1.Button1Click(Sender: TObject);
    begin
             ExitWindowsEx(EWX_REBOOT,0);
    end;
    这样好像不行呀。
      

  7.   

    procedure TForm1.Button1Click(Sender: TObject);
    var
      ret:boolean;
    begin
      ret:=ExitWindowsEx(EWX_REBOOT,0);
    end;
      

  8.   

    出现一个Information 对话框。       Debug session in progress.  Terminate?            OK      Cancel        Help
      

  9.   

    Ok后出现
    Accessviolation at address 40025871 in module 'VCL50.BPL'.
    Read of address FFFFFFFF.                   O K的错误。并出现程序没有响应的提示。我选等待,并确定上面的错误框。系统重启成功。请问这是为什么?我想知其然并知其所以然。
      

  10.   

    好啦,帮你找到答案了:
    把 "EWX_REBOOT" 改为  "EWX_REBOOT or EWX_POWEROFF" 就成了!总结:
    在重启或关闭计算机时,uFlags 应再补充 EWX_POWEROFF 常量。
    (可是再 VB 中并不需要这样啊!) 
      

  11.   

    好像我这里改与不改运行结果是一样的呀!还有。我发现了。
    在DELPHI开发时用F9运行时会出现Debug session in progress.  Terminate?的信息框。如果直接运行编译后的程序,就不会出现了。但是,都会出现Accessviolation at address 40025871 in module 'VCL50.BPL'.
    Read of address FFFFFFFF这个错误。真是不知道为什么。有没有哪个高手知道呀
      

  12.   

    是你的vcl库有问题吧?
    module 'VCL50.BPL'
      

  13.   

    不会吧。VCL50。BPL是用来干什么的呀
      

  14.   

    msdn中关于api函数--ExitWindowsEx说的很清楚!有一点英文功底都可以了!