VB API函数(ExitWindowEx)

  利用ExitWindowEx实现最简单的关机功能

  Private Declare Function ExitWindowsEx Lib "user32" (ByVal uFlags As Long, ByVal dwReserved As Long) As Long

  参数:

  uFlags:     Long  //指定关闭的类型,类型有:

EWX_FORCE  //强制终止进程

EWX_LOGOFF    //关闭所有进程,然后注销用户

EWX_POWEROFF  //关闭系统并关闭电源

EWX_REBOOT    //关闭系统,然后重新启动系统

EWX_SHUTDOWN //关闭系统,安全地关闭电源

dwReserved:   Long  // 系统保留,一般为0

代码实现如下

 

Option Explicit
Private Declare Function ExitWindowsEx Lib "user32" (ByVal uFlags As Long, ByVal dwReserved As Long) As Long
Private Const EWX_FORCE = 4    '强制终止进程
Private Const EWX_LOGOFF = 0   '关闭所有进程,然后注销用户
Private Const EWX_REBOOT = 2   '关闭系统,然后重新启动系统
Private Const EWX_SHUTDOWN = 1 '关闭系统,安全地关闭电源。

Private Sub Command1_Click()
 Dim i As Long
 i = ExitWindowsEx(EWX_REBOOT, 0)
 
End Sub

 

 

  

posted @ 2014-10-22 20:03  Delphi爱好者2014  阅读(493)  评论(0编辑  收藏  举报