当前位置:编程学习 > VB >>

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 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

上一个:vb控制摄像头代码
下一个:关于VB基础

CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,