first, WindowsIdentity.GetCurrent has an overload that you can use to determine
if you are currently impersonating.
then you can undo impersonation temporarily to get to the process account
do this
using (WindowsIdentity.Impersonate(IntPtr.Zero))
{
string process = WindowsIdentity.GetCurrent();
}
from the docs:
"Calling the Impersonate(IntPtr) method with a userToken value of Zero is
equivalent to calling the Win32 RevertToSelf function. If another user is
currently being impersonated, control reverts to the original user."
-----
Dominick Baier (http://www.leastprivilege.com)
Developing More Secure Microsoft ASP.NET 2.0 Applications (http://www.microsoft.com/mspress/books/9989.asp)
> System.Security.Principal.WindowsIdentity.GetCurrent() can give me the
> current logged-on user, but I found if I'm using impersonation in the
> context, it can only give me the user identity who's being
> impersonated rather than the real logged user on the Windows, what if
> I want the latter?
despird - 15 May 2008 13:04 GMT
On May 15, 5:40 pm, Dominick Baier
<dbaier@pleasepleasenospam_leastprivilege.com> wrote:
> first, WindowsIdentity.GetCurrent has an overload that you can use to determine
> if you are currently impersonating.
[quoted text clipped - 26 lines]
>
> - Show quoted text -
that seems to be a very plausible solution, i'll try it again tomorrow
thanks a lot.
despird - 16 May 2008 01:41 GMT
> On May 15, 5:40 pm, Dominick Baier
>
[quoted text clipped - 34 lines]
>
> - Show quoted text -
that does work, thanks a lot Dominick