发表于:2006-09-28 09:26:00
9楼
发一个退出windows2000的代码 这下你该满足了吧 嘿嘿
Option Explicit
'*******************************************************************
'Shut Down Windows
'Free Softwear
'Programed By Sproll
'You Can Communicat Him With E-Mail sproll@163.com
'
'*******************************************************************
Private Declare Function ExitWindowsEx Lib "user32" (ByVal uFlags As Long, ByVal dwReserved As Long) As Long
Private Declare Function AdjustTokenPrivileges Lib "advapi32.dll" (ByVal TokenHandle As Long, ByVal DisableAllPrivileges AsLong, NewState As TOKEN_PRIVILEGES, ByVal BufferLength As Long, PreviousState As Long, ReturnLength As Long) As Long
Private Declare Function GetTokenInformation Lib "advapi32.dll" (ByVal TokenHandle As Long, ByVal TokenInformationClass As Long, TokenInformation As Any, ByVal TokenInformationLength As Long, ReturnLength As Long) As Long
Private Declare Function LookupPrivilegeValue Lib "advapi32.dll" Alias "LookupPrivilegeValueA" (ByVal lpSystemName As String, ByVal lpName As String, ByRef lpLuid As LARGE_INTEGER) As Long
Private Declare Function OpenProcessToken Lib "advapi32.dll" (ByVal ProcessHandle As Long, ByVal DesiredAccess As Long, TokenHandle As Long) As Long
Private Declare Function GetCurrentProcessId Lib "kernel32" () As Long
Private Declare Function GetCurrentProcess Lib "kernel32" () As Long
Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Private Const EWX_LOGOFF = 0 '注销当前用户
Private Const EWX_POWEROFF = 8 '关闭系统并关闭电源
Private Const EWX_SHUTDOWN = 1 '关闭系统使之能安全关闭电源
Private Const EWX_REBOOT = 2 '关闭系统并重启
Private Const EWX_FORCE = 4 '应用程序强制关闭
Private Const EWX_FORCEIFHUNG = 16 '如果应用程序已挂起,强制关闭
Private Const SE_PRIVILEGE_ENABLED = &H2
Private Const SE_PRIVILEGE_ENABLED_BY_DEFAULT = &H1
Private Const SE_PRIVILEGE_USED_FOR_ACCESS = &H80000000
Private Const TOKEN_ADJUST_PRIVILEGES = &H20
Private Const TOKEN_QUERY_SOURCE = &H10
Private Const TOKEN_QUERY = &H8
Private Const ANYSIZE_ARRAY = 1
Private Const SE_SHUTDOWN_NAME = "SeShutdownPrivilege"
Private Const PROCESS_SET_INFORMATION = &H200
Private Const PROCESS_QUERY_INFORMATION = &H400
Private Type LARGE_INTEGER
lowpart As Long
highpart As Long
End Type
Private Type LUID
lowpart As Long
highpart As Long
End Type
Private Type LUID_AND_ATTRIBUTES
pLuid As LUID
Attributes As Long
End Type
Private Type TOKEN_PRIVILEGES
PrivilegeCount As Long
Privileges(0) As LUID_AND_ATTRIBUTES
End Type
Private Sub Command1_Click()
Dim lAPIReturn As Long
Dim tTOKPRI As TOKEN_PRIVILEGES
Dim tLUID As LUID
Dim tLarInt As LARGE_INTEGER
Dim lRequired As Long
Dim hTokHan As Long
Dim hProcess As Long
If LookupPrivilegeValue(vbNullString, SE_SHUTDOWN_NAME, tLarInt) = 0 Then
MsgBox "Get LUID error!", vbOKOnly, "Error"
Exit Sub
End If
tLUID.highpart = tLarInt.highpart
tLUID.lowpart = tLarInt.lowpart
tTOKPRI.PrivilegeCount = 1
tTOKPRI.Privileges(0).Attributes = SE_PRIVILEGE_ENABLED
tTOKPRI.Privileges(0).pLuid = tLUID
hProcess = GetCurrentProcess()
lAPIReturn = OpenProcessToken(hProcess, TOKEN_ADJUST_PRIVILEGES + TOKEN_QUERY, hTokHan)
lAPIReturn = AdjustTokenPrivileges(hTokHan, 0, tTOKPRI, Len(tTOKPRI), 0, 0)
' lAPIReturn = ExitWindowsEx(EWX_LOGOFF, 0)
' lAPIReturn = ExitWindowsEx(EWX_SHUTDOWN, 0)
' lAPIReturn = ExitWindowsEx(EWX_POWEROFF, 0)
' lAPIReturn = ExitWindowsEx(EWX_REBOOT, 0)
' lAPIReturn = ExitWindowsEx(EWX_FORCE, 0)
lAPIReturn = ExitWindowsEx(EWX_REBOOT, 0) '关键之处就在这里了,想要做什么随你便了
If lAPIReturn = 0 Then
MsgBox "Function calling error!", vbOKOnly, "错误"
End If
lAPIReturn = CloseHandle(hTokHan)
End Sub