471,047 Members | 1,242 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,047 software developers and data experts.

vbusing impersonation in vb.net


I am still struggling with impersonation in vb.net. I have a service that
logs on to exchange but I get different results when using the "log on as"
feature on the service as opposed to the impersonation routine. I am very
curious about how that is possible. It should yield the same results

Has anyone else used impersonation in a vb.net service?

The routine i am using is from an article on msdn (if i recall correctly)
and is printed at the end of this message. I run this at the very start of
the service, and do the Undo() function when the service ends so that ALL
the code in the service is supposed to run as the given user.

Thanks for any feedback,
Public Function impersonateValidUser(ByVal userName As String, ByVal
domain As String, ByVal password As String) As Boolean

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,
If DuplicateToken(token, 2, tokenDuplicate) <> 0 Then
tempWindowsIdentity = New
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
End If
If Not token.Equals(IntPtr.Zero) Then
End If
End Function
Nov 20 '05 #1
0 3915

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Ripa Horatiu | last post: by
11 posts views Thread by Phil | last post: by
1 post views Thread by Patrick | last post: by
reply views Thread by velvet.graham | last post: by
5 posts views Thread by =?Utf-8?B?S2l0dHlIYXdr?= | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.