vb提权代码
需要详细的代码
需要详细的代码
答案: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 TypePublic Type LUID_AND_ATTRIBUTES
pLuid As Luid
Attributes As Long
End TypePublic 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 FunctionEnd If
' lResult = SetPrivilege(hToken, SE_DEBUG_NAME, True)
lResult = SetPrivilege(hToken, sPrivilegeName, True)
If (lResult = False) ThenCloseHandle (hToken)
getPrivileges = False
Exit FunctionEnd If
getPrivileges = True
hhToken = hToken
End Function