Impersonate Issues to note



I've been trying to use ImpersonateSelf here, and ran into a few problems. I
just want to jot them down in case anyone else finds them useful.

To start with, the API TextViewer declaration is wrong. It declares it as:

Private Declare Function ImpersonateSelf Lib "advapi32.dll"
(ImpersonationLevel As Integer) As Long

but this gives parameter validation errors. After looking at the C header
file, I changed it to the following and it was a lot better:

Private Declare Function ImpersonateSelf Lib "advapi32.dll" (ByVal
ImpersonationLevel As Long) As Long

The next problem is the definition of the SECURITY_IMPERSONATION_LEVEL
values. The API TextViewer gives just:

Private Const SecurityAnonymous = 1
Private Const SecurityIdentification = 2

even though these blatantly disagree with the MSDN documentation. I noticed
that a lot of old posts also seem to use these bad values. Again, after
looking at the C header files, I used the following definition instead:

Private Enum SECURITY_IMPERSONATION_LEVEL
SecurityAnonymous = 0
SecurityIdentification
SecurityImpersonation
SecurityDelegation
End Enum

Tony Proctor


.



Relevant Pages

  • Re: Impersonate Issues to note
    ... that title should have been "ImpersonateSelf issues to note". ... the API TextViewer declaration is wrong. ... Private Declare Function ImpersonateSelf Lib "advapi32.dll" (ByVal ... SecurityIdentification ...
    (microsoft.public.vb.winapi)
  • Re: VB6 - ImpersonateLoggedOnUser - Virtualization - VirtualStore
    ... Private Declare Function ImpersonateLoggedOnUser Lib "advapi32.dll" _ ... Public Function ImpersonateSelf() As Boolean ... If mbImpersonating Then StopImpersonation ...
    (microsoft.public.vb.general.discussion)
  • Re: Impersonate Issues to note
    ... Private Declare Function ImpersonateSelf Lib "advapi32.dll" (ByVal ... SecurityIdentification ...
    (microsoft.public.vb.winapi)