vb提权代码
发布网友
发布时间:2024-08-19 07:19
我来回答
共1个回答
热心网友
时间:2024-08-22 16:26
Private hhToken As Long
'权限常数
Public Const SE_DEBUG_NAME = "SeDebugPrivilege"
Public Const SE_SHUTDOWN_NAME = "SeShutdownPrivilege"
Public Const SE_PRIVILEGE_ENABLED = &H2
Public Const TOKEN_ADJUST_PRIVILEGES = &H20
Public Const TOKEN_QUERY = &H8
Public Const ANYSIZE_ARRAY = 1
Public Type Luid
lowpart As Long
highpart As Long
End Type Public Type LUID_AND_ATTRIBUTES
pLuid As Luid
Attributes As Long
End Type Public Type TOKEN_PRIVILEGES
PrivilegeCount As Long
Privileges(ANYSIZE_ARRAY) As LUID_AND_ATTRIBUTES
End Type
Public Type FILETIME ' 8 Bytes
dwLowDateTime As Long
dwHighDateTime As Long
End Type
Declare Function GetCurrentProcess Lib "Kernel32" () As Long
Declare Function OpenProcessToken Lib "advapi32.dll" (ByVal ProcessHandle As Long, ByVal DesiredAccess As Long, TokenHandle As Long) As Long
Public Function getPrivileges(hhToken As Long, ByVal sPrivilegeName As String) As Boolean
Dim hProcessID As Long ' Handle to your sample
' process you are going to
' terminate.
Dim hProcess As Long ' Handle to your current process
' (Term02.exe).
Dim hToken As Long ' Handle to your process token.
Dim lPrivilege As Long ' Privilege to enable/disable
Dim iPrivilegeflag As Boolean ' Flag whether to enable/disable
' the privilege of concern.
Dim lResult As Long ' Result call of various APIs. getPrivileges = False
'hProcessID = ApplicationPID ' get our current process handle
hProcess = GetCurrentProcess
lResult = OpenProcessToken(hProcess, TOKEN_ADJUST_PRIVILEGES Or _
TOKEN_QUERY, hToken)
If (lResult = 0) Then
CloseHandle (hToken)
getPrivileges = False
Exit Function End If' lResult = SetPrivilege(hToken, SE_DEBUG_NAME, True)
lResult = SetPrivilege(hToken, sPrivilegeName, True)
If (lResult = False) Then CloseHandle (hToken)
getPrivileges = False
Exit Function End If
getPrivileges = True
hhToken = hToken
End Function