如何用 VB6.0 代码关闭 Windows XP 系统

怎么用 VB6.0 代码关闭 Windows XP 系统?
大家好!

怎么用   VB6.0   代码关闭   Windows   XP   系统?
谢谢!

------解决方案--------------------
在公共标准模块中声明WIN API:
Public Declare Function ExitWindowsEx Lib "user32 " (ByVal uFlags As Long, ByVal dwReserved As Long) As Long

在按钮事件中用如下代码可关机:
Private Sub Command1_Click()
ExitWindowsEx 1, 0
End Sub

在按钮事件中用如下代码可重启:
Private Sub Command1_Click()
ExitWindowsEx 2, 0
End Sub

------解决方案--------------------
<98 下的代码>

Private Declare Function ExitWindows Lib "user32 " (ByVal dwReserved As Long, ByVal uReturnCode 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 execute(op as string)
Select Case op
Case "关机 "
ExitWindows EWX_SHUTDOWN, 0
Case "重启 "
ExitWindows EWX_REBOOT, 0
Case "注销 "
ExitWindows EWX_LOGOFF, 0
End Select
End Sub

==============================================================================

<2000 和 xp 下的代码>

Private Declare Function ExitWindowsEx Lib "user32 " (ByVal uFlags As Long, ByVal dwReserved As Long) As Long
Private Declare Function GetCurrentProcess Lib "kernel32 " () As Long
Private Declare Function LookupPrivilegeValue Lib "advapi32.dll " Alias "LookupPrivilegeValueA " (ByVal lpSystemName As String, ByVal lpName As String, lpLuid As LUID) As Long
Private Declare Function AdjustTokenPrivileges Lib "advapi32.dll " (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
Private Declare Function OpenProcessToken Lib "advapi32.dll " (ByVal ProcessHandle As Long, ByVal DesiredAccess As Long, TokenHandle As Long) As Long

Private Const ANYSIZE_ARRAY = 1 '--------AT
Private Const TOKEN_ADJUST_PRIVILEGES = &H20 '--------AT
Private Const TOKEN_QUERY = &H8 '--------AT
Private Const SE_PRIVILEGE_ENABLED = &H2 '--------AT

Sub AdjustToken()
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
LookupPrivilegeValue " ", "SeShutdownPrivilege ", tmpLuid
tkp.PrivilegeCount = 1 ' One privilege to set
tkp.Privileges(0).pLuid = tmpLuid
tkp.Privileges(0).Attributes = SE_PRIVILEGE_ENABLED
'Get the LUID for shutdown privilege.

AdjustTokenPrivileges hdlTokenHandle, False, tkp, Len(tkpNewButIgnored), tkpNewButIgnored, lBufferNeeded
'Enable the shutdown privilege in the access token of this process.
End Sub

Private Sub execute(op as string) '--------AT
Call AdjustToken

Select Case op
Case "注销 "
ExitWindowsEx EWX_LOGOFF, 0
Case "关闭 "
ExitWindowsEx EWX_SHUTDOWN, 0
Case "重启 "
ExitWindowsEx EWX_REBOOT, 0
Case "强制关闭 "
ExitWindowsEx EWX_FORCE, 0
End Select