在我程序中有一重启计算机的命令,当我执行它后,将所有正在运行的程序全部关掉,然后重启。怎样才能做到?现在我执行后,如有其他程序在运行,做了修改的话,总是会提示"内容已经修改,是否保存?",我不想有这样的提示,而让它自己关掉,不用保存,就像有些安装程序一样,执行完毕后关掉所有程序自己重启,怎样做到?

解决方案 »

  1.   

    ExitWindowsEx(EWX_FORCE,4); //强行关机 
    可以吗?
      

  2.   

    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.我想你的意思能满足了,散分,谢谢
      

  3.   

    我没说清楚,因为我在FormClose中有东西要执行,所以在关机之前就必须要有WM_QUERYENDSESSION 消息,但EWX_FORCE 是不发此消息的,而且在Win2k中用AdjustToken得到关机权限后用EWX_FORCE后是会出错的