Re: Impersonate via a remote workgroup



sorry. this only works if you are trying to access remote resources that "know" the account you are impersonating.

---------------------------------------
Dominick Baier - DevelopMentor
http://www.leastprivilege.com

i am trying to impersanate a remote user on a workgroup(NOT Domain)
account. This does not seem to work. Only works for domain or local
user. Anyone have any ideas.

Thanks

Dim tempWindowsIdentity As WindowsIdentity
Dim token As IntPtr = IntPtr.Zero
Dim tokenDuplicate As IntPtr = IntPtr.Zero
impersonateValidUser = False
If RevertToSelf() Then
If LogonUserA(userName, domain, password,
LOGON32_LOGON_INTERACTIVE, LOGON32_PROVIDER_DEFAULT, token) <> 0 Then
If DuplicateToken(token, 2, tokenDuplicate) <> 0 Then
tempWindowsIdentity = New
WindowsIdentity(tokenDuplicate)
impersonationContext =
tempWindowsIdentity.Impersonate()
If Not impersonationContext Is Nothing Then
impersonateValidUser = True
End If
End If
End If
End If
If Not tokenDuplicate.Equals(IntPtr.Zero) Then
CloseHandle(tokenDuplicate)
End If
If Not token.Equals(IntPtr.Zero) Then
CloseHandle(token)
End If


.



Relevant Pages

  • Re: Impersonate via a remote workgroup
    ... Dim tempWindowsIdentity As WindowsIdentity ... Dim tokenDuplicate As IntPtr = IntPtr.Zero ... impersonateValidUser = False ...
    (microsoft.public.dotnet.framework.aspnet.security)
  • Re: logonuser api returns 127
    ... > String, ByVal lpszDomain As String, ByVal lpszPassword As String, ByVal ... > Dim LogonProvider As Integer ... > impersonateValidUser = False ... are you absolutely sure that GetLastError is returning ...
    (microsoft.public.dotnet.languages.vb)
  • Impersonation half way working
    ... Dim LOGON32_LOGON_INTERACTIVE As Integer = 2 ... ByVal lpszDomain As String, _ ... ExistingTokenHandle As IntPtr, ByVal ImpersonationLevel As Integer, ByRef ... impersonateValidUser = False ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Impersonation half way working
    ... > Dim impersonationContext As WindowsImpersonationContext ... > ByVal lpszDomain As String, ... > ExistingTokenHandle As IntPtr, ByVal ImpersonationLevel As Integer, ByRef ... > impersonateValidUser = False ...
    (microsoft.public.dotnet.languages.vb)