Public Delcare Function ExitWindows Lib "user32" Alias "ExitWindows" (ByVal dwReserved As Long, ByVal uReturnCode As Long) As Long

解决方案 »

  1.   

    系统重启与关机的事例 
    实现系统的重新启动。其方法是调用Windows的应用接口函 
    数API:ExitWindows。它支持两个参数。第一个参数决定了退出Windows的方式。 
    可选择参数有:&h42~重新启动Windows、&h43~系统热启动,第二个参数为恒为0。 
    建立应用程序的步骤如下: (1)进入Visual Basic设计环境,新建一个工程项目Project1,在窗体中设置 
    按钮数组Command1(0)、Command1(1)和Command1(3).各个对象的属性如下: 
    form1: caption:启动工具 
    backcolor:&H00C0C0C0& 
    command1(0) caption:程序重新启动Windows 
    command1(1) caption:系统热启动 
    Command1(3) caption:退出 
    (2)代码设计。首先在窗体的通用代码区(General)内对所调用的 
    WindowsAPI函数进行声明如下: 
    Declare Function exitwindows Lib "User" (ByVal dwReturnCode As 
    Long, ByVal wReserved As Integer) As Integer 
    程序代码如下: 
    Sub Command1_Click (index As Integer) 
    Select Case index 
    Case 0 
    i = exitwindows(&H43, 0)’热启动 
    Case 1 
    i = exitwindows(&H42, 0)’重新启动Windows 
    Case 3 
    End ’退出 
    End Select 
    End Sub 
    如何关闭计算机?
    '声明 
    Declare Function ExitWindows Lib "User" (ByVal dwReturnCode As Long, ByVal wReserved As Integer) As Integer
    '执行 
    Dim DUMMY 
    DUMMY=ExitWindows(0,0) 
    还可以用另一种方法:直接调用系统重启,关机应用程序
    调用重启:reset=shell("c:\windows\rundll.exe user.exe,exitwindowexec",1)
    调用关机:exit=shell("c:\windows\rundll.exe user.exe,exitwindow",1)
     
      

  2.   

    Private Declare Function ExitWindowsEx Lib "user32" (ByVal uFlags As Long, ByVal dwReserved As Long) As Long
    '说明
    '退出windows,并用特定的选项重新启动
    Private Const EWX_FORCE = 4   '强迫中止没有响应的进程
    Private Const EWX_LOGOFF = 0  '中止进程,然后注销
    Private Const EWX_REBOOT = 2  '重新引导系统
    Private Const EWX_SHUTDOWN = 1 '关闭系统