On Jul 12, 1:51 pm, "Juan T. Llibre" <nomailrepl...@nowhere.com>
wrote:
> IIRC, The background thread executes under the Application Pool identity.
> Make sure you pass the correct identity to the Jet OleDb provider.
[quoted text clipped - 26 lines]
>
> > Seth Rowe
> On Jul 12, 1:51 pm, "Juan T. Llibre" <nomailrepl...@nowhere.com>
> wrote:
[quoted text clipped - 40 lines]
>
> Seth Rowe
Okay, in the end I didn't use either of your suggestions, but crafted
my own based on some API documentation I read through.
Below is my solution if any future archive browsers need it:
//////////////////
Imports System.Security.Principal
Imports System.Runtime.InteropServices
Public Class MyClassToBeThreaded
<DllImport("advapi32.dll")> _
Protected Shared Function LogonUser(ByVal lpszUserName As String,
_
ByVal lpszDomain As String, _
ByVal lpszPassword As String, _
ByVal dwLogonType As Integer, _
ByVal dwLogonProvider As Integer,
_
ByRef phToken As IntPtr) As
Boolean
End Function
'// This is the thread to be called asynchronously,
'// so do the impersonation calls here
Public Sub DoTheWork()
Try
Dim hToken As IntPtr
If LogonUser("username", "domain", "password", 2, 0,
hToken) Then
Using wi As WindowsIdentity = New
WindowsIdentity(hToken), wic As WindowsImpersonationContext =
wi.Impersonate()
'// Do the actually work here
End Using
End If
Catch
'// Handle the exception if the impersonation
'// blows up in your face :-)
End Try
End Sub
End Class
/////////////////////
Thanks,
Seth Rowe
Juan T. Llibre - 13 Jul 2007 18:57 GMT
re:
!> Okay, in the end I didn't use either of your suggestions, but crafted
!> my own based on some API documentation I read through.
Fantastic, Seth!
Thanks for sharing the code.
It should help someone down the line...
Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
======================================
> On Jul 12, 1:51 pm, "Juan T. Llibre" <nomailrepl...@nowhere.com>
> wrote:
[quoted text clipped - 42 lines]
>
> Seth Rowe
Okay, in the end I didn't use either of your suggestions, but crafted
my own based on some API documentation I read through.
Below is my solution if any future archive browsers need it:
//////////////////
Imports System.Security.Principal
Imports System.Runtime.InteropServices
Public Class MyClassToBeThreaded
<DllImport("advapi32.dll")> _
Protected Shared Function LogonUser(ByVal lpszUserName As String,
_
ByVal lpszDomain As String, _
ByVal lpszPassword As String, _
ByVal dwLogonType As Integer, _
ByVal dwLogonProvider As Integer,
_
ByRef phToken As IntPtr) As
Boolean
End Function
'// This is the thread to be called asynchronously,
'// so do the impersonation calls here
Public Sub DoTheWork()
Try
Dim hToken As IntPtr
If LogonUser("username", "domain", "password", 2, 0,
hToken) Then
Using wi As WindowsIdentity = New
WindowsIdentity(hToken), wic As WindowsImpersonationContext =
wi.Impersonate()
'// Do the actually work here
End Using
End If
Catch
'// Handle the exception if the impersonation
'// blows up in your face :-)
End Try
End Sub
End Class
/////////////////////
Thanks,
Seth Rowe