0

I'm using SimpleImpersonation package, which does dirty work around some extern functions, for example

[DllImport("advapi32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
internal static extern bool LogonUser(string lpszUsername, string lpszDomain, string lpszPassword, int dwLogonType, int dwLogonProvider, out IntPtr phToken);

I'm using it like this:

using (var imp = Impersonation.LogonUser(domain, user, password, LogonType.Interactive))
{
    // another user
}
//me again

The problem is that this method impersonates user only for current thread, while I need to perform actions under another credentials from all threads in my application. How to achieve this?

astef
  • 8,575
  • 4
  • 56
  • 95
  • I am not sure what you are looking for here. You have successfully impersonated a section of code, then you ask "for this other section of code that I dont show you, how do I impersonate that?" – crthompson Feb 24 '15 at 16:10
  • Don't focus on my exact code, just tell me, how to impersonate the whole process, but not the single thread. In other words, how to use once impersonated credentials in every thread of an application? – astef Feb 24 '15 at 16:15
  • create other threads in impersonated thread :) – EZI Feb 24 '15 at 16:23
  • @EZI that is too difficult in my project, even changing each worker's thread to impersonate is overkill. Also I need to change user frequently, not only at application startup – astef Feb 24 '15 at 16:26
  • Sounds like you need to refactor. – crthompson Feb 24 '15 at 16:35
  • @paqogomez Ofcource I need. Every program needs it, to some extent. But we are programmers to release products, not for coding, right? – astef Feb 24 '15 at 16:40

0 Answers0