Private Enum TOKEN_TYPE TokenPrimary=1 TokenImpersonation End Enum
Private Enum SECURITY_IMPERSONATION_LEVEL SecurityAnonymous=0 SecurityIdentification SecurityImpersonation SecurityDelegation End Enum Private Declare Function LogonUser Lib "advapi32. DLL Alias" _ "LogonUserA" _ (ByVal lpszUsername As String, _ ByVal lpszDomain As String, _ ByVal lpszPassword As String, _ ByVal dwLogonType As Long, _ ByVal dwLogonProvider As Long, _ PhToken As Long As Long)
Private Declare Function DuplicateTokenEx _ Lib "advapi32. DLL" (ByVal hExistingToken As Long, _ ByVal dwDesiredAccess As Long, _ ByVal lpTokenAttributes As Long, _ ImpersonationLevel As SECURITY_IMPERSONATION_LEVEL, _ ByVal TokenType As TOKEN_TYPE, _ PhNewToken As Long) As Boolean
Private Sub Command1_Click () Dim the Result As Long Dim htoken As Long Dim hNewToken As Long, As Long I Result=LogonUser (" Administrator ", ""," 111 ", LOGON32_LOGON_INTERACTIVE, LOGON32_PROVIDER_DEFAULT, htoken) MsgBox htoken MsgBox DuplicateTokenEx (htoken, 0, I, SECURITY_IMPERSONATION_LEVEL SecurityImpersonation, TOKEN_TYPE. TokenPrimary, hNewToken) MsgBox hNewToken End Sub
Want hNewToken values, the code in the xp environment can get the result, but not under Windows 7, should be user permissions, Hope ace to give the solution
CodePudding user response:
You must make your program "with administrator," Program without permission is not oneself up permissions, otherwise the safety of the system is false,