AdjustTokenPrivileges获取权限实现关机问题
Option Explicit
Public Declare Function GetCurrentProcess Lib "kernel32" () As Long
Public Declare Function OpenProcessToken Lib "advapi32.dll" _
(ByVal ProcessHandle As Long, ByVal DesiredAccess As Long, TokenHandle As Long) _
As Long
Public Declare Function LookupPrivilegeValue Lib "advapi32.dll" Alias "LookupPrivilegeValueA" _
(ByVal lpSystemName As String, ByVal lpName As String, lpLuid As LARGE_INTEGER) _
As Long
Public 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
Public Declare Function ExitWindowsEx Lib "user32" _
(ByVal uFlags As Long, ByVal dwReserved As Long) As Long
'----------------------------------------------
'ExitWindowsEX常数
Public Const EWX_FORCE = 4
Public Const EWX_LOGOFF = 0
Public Const EWX_REBOOT = 2
Public Const EWX_SHUTDOWN = 1
'-----------------------------------------------
Public Const SE_SECURITY_NAME = "SeSecurityPrivilege"
Public Const SE_PRIVILEGE_ENABLED = &H2
Public Const TOKEN_ADJUST_PRIVILEGES = &H20
'----------------------------------------------
Public Type LARGE_INTEGER
lowpart As Long
highpart As Long
End Type
Public Type LARGE_INTEGER_AND_ATTRIBUTES
pLuid As LARGE_INTEGER
Attributes As Long
End Type
Public Type TOKEN_PRIVILEGES
PrivilegeCount As Integer
Privileges As LARGE_INTEGER_AND_ATTRIBUTES
End Type
Private Sub Command1_Click()
Dim jieshou As Long
Dim jieshou1 As Long
Dim q As TOKEN_PRIVILEGES
Dim w As LARGE_INTEGER
Dim Privileges As TOKEN_PRIVILEGES
Dim e As Long
Dim PrevNeed As Long
q.PrivilegeCount = 1
q.Privileges.Attributes = SE_PRIVILEGE_ENABLED
q.Privileges.pLuid = w
e = Len(Privileges)
jieshou1 = OpenProcessToken(GetCurrentProcess(), SE_SECURITY_NAME, jieshou)
AdjustTokenPrivileges jieshou1, False, q, e '最后那个参数应该怎么放啊?
ExitWindowsEx 0, EWX_LOGOFF
End Sub