16位Windows用ExitWindows() API函数,而32位Windows则用ExitWindowsEx().32位版本比16位版本多了更多的控制及选项,包括注销及关机。 Declare Function ExitWindows Lib "user" (ByVal uFlags As Long, ByVal _ 
dwReserved As integer) As integer 
Const EW_REBOOTSYSTEM = &H43 
Const EW_RESTARTWINDOWS = &H42 Sub Command1_Click() Dim rVal As Integer rVal = ExitWindows(EW_REBOOTSYSTEM, 0) End Sub ***** 32位的例子 ***** 
Private Declare Function ExitWindowsEx Lib "user32" (ByVal uFlags As Long, _ 
ByVal dwReserved As Long) As Long 
Private Const EWX_LOGOFF = 0 
Private Const EWX_SHUTDOWN = 1 
Private Const EWX_REBOOT = 2 
Private Const EWX_FORCE = 4 Private Sub Command1_Click() Dim rVal As Long rVal = ExitWindowsEx(EWX_SHUTDOWN, 0&) End Sub 

解决方案 »

  1.   

    使用API函数
    Exitwindows 1,1关机
    exitwindows 2,1重启
    ExitWindows 0,1注消
    可能实现
      

  2.   

    如果win95,98以上的方法就可以了,如果是winNT,wind2000还要设置权限,以下是我用在2000下的代码。Option ExplicitPrivate Type LUID
      UsedPart As Long
      IgnoredForNowHigh32BitPart As Long
    End TypePrivate Type TOKEN_PRIVILEGES
      PrivilegeCount As Long
      TheLuid As LUID
      Attributes As Long
    End TypePrivate Const EWX_SHUTDOWN As Long = 1
    Private Const EWX_FORCE As Long = 4
    Private Const EWX_REBOOT = 2
    Private Const EWX_POWEROFF = 8Private Declare Function ExitWindowsEx Lib "user32" (ByVal _
         dwOptions As Long, ByVal dwReserved As Long) As Long
    Private Declare Function GetCurrentProcess Lib "kernel32" () As Long
    Private Declare Function OpenProcessToken Lib "advapi32" (ByVal _
       ProcessHandle As Long, _
       ByVal DesiredAccess As Long, TokenHandle As Long) As Long
    Private Declare Function LookupPrivilegeValue Lib "advapi32" _
       Alias "LookupPrivilegeValueA" _
       (ByVal lpSystemName As String, ByVal lpName As String, lpLuid _
       As LUID) As Long
    Private Declare Function AdjustTokenPrivileges Lib "advapi32" _
       (ByVal TokenHandle As Long, _
       ByVal DisableAllPrivileges As Long, NewState As TOKEN_PRIVILEGES _
       , ByVal BufferLength As Long, _
    PreviousState As TOKEN_PRIVILEGES, ReturnLength As Long) As Long
    Public Sub Main()
        Dim I As Long
        
        I = StandardShutdown()
        
    End SubPublic Function StandardShutdown() As Long'Function to perform a standard shutdown of Windows.  Needs to be a
    'global function since it is called from more than one procedure.
    AdjustToken
    StandardShutdown = ExitWindowsEx(EWX_SHUTDOWN Or EWX_FORCE Or EWX_POWEROFF, 0&)End Function
    Private Sub AdjustToken()
        Const TOKEN_ADJUST_PRIVILEGES = &H20
        Const TOKEN_QUERY = &H8
        Const SE_PRIVILEGE_ENABLED = &H2
        Dim hdlProcessHandle As Long
        Dim hdlTokenHandle As Long
        Dim tmpLuid As LUID
        Dim tkp As TOKEN_PRIVILEGES
        Dim tkpNewButIgnored As TOKEN_PRIVILEGES
        Dim lBufferNeeded As Long    hdlProcessHandle = GetCurrentProcess()
        OpenProcessToken hdlProcessHandle, (TOKEN_ADJUST_PRIVILEGES Or _
           TOKEN_QUERY), hdlTokenHandle ' Get the LUID for shutdown privilege
        LookupPrivilegeValue "", "SeShutdownPrivilege", tmpLuid    tkp.PrivilegeCount = 1    ' One privilege to set
        tkp.TheLuid = tmpLuid
        tkp.Attributes = SE_PRIVILEGE_ENABLED' Enable the shutdown privilege in the access token of this process
        AdjustTokenPrivileges hdlTokenHandle, False, _
        tkp, Len(tkpNewButIgnored), tkpNewButIgnored, lBufferNeededEnd Sub