Попробуй так:
Private Const ANYSIZE_ARRAY = 1
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(ANYSIZE_ARRAY) As LUID_AND_ATTRIBUTES
End Type
Private Enum eParam
EWX_LOGOFF = 0
EWX_SHUTDOWN = 1
EWX_REBOOT = 2
EWX_FORCE = 4
End Enum
Private Declare Function ExitWindowsEx Lib "user32" (ByVal uFlags As Long, ByVal dwReserved 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 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 GetCurrentProcess Lib "kernel32" () As Long
Private Function ShutdownEx(ByVal fParam As eParam) As Boolean
Dim Ret As Long
Dim hToken As Long
Dim Tkp As TOKEN_PRIVILEGES
Dim TkpOld As TOKEN_PRIVILEGES
Dim aOkReboot As Boolean
Const SE_SHUTDOWN_NAME = "SeShutdownPrivilege"
If ((fParam And EWX_SHUTDOWN) = EWX_SHUTDOWN) Or ((fParam And EWX_REBOOT) = EWX_REBOOT) Then
If OpenProcessToken(GetCurrentProcess(), 32 Or 8, hToken) Then
Ret = LookupPrivilegeValue(vbNullString, SE_SHUTDOWN_NAME, Tkp.Privileges(0).pLuid)
Tkp.PrivilegeCount = 1
Tkp.Privileges(0).Attributes = 2
aOkReboot = AdjustTokenPrivileges(hToken, 0, Tkp, LenB(TkpOld), TkpOld, Ret)
End If
End If
ShutdownEx = (ExitWindowsEx(fParam, 0) <> 0)
End Function
ShutdownEx EWX_SHUTDOWN Это в кнопке
Ответить
|