It doesn't work this way. Processes created with the Process class inherit
the process token, not the impersonated token. The Process class allows you
to specify credentials in .NET 2.0, but I don't know if that would help you
in your use case, as you don't have the user's password.
You could try calling CreateProcessWithTokenW, but you'd probably also need
to call DuplicateTokenEx to convert the impersonation token in the
WindowsIdentity into a primary token.
Joe K.

Signature
Joe Kaplan-MS MVP Directory Services Programming
Co-author of "The .NET Developer's Guide to Directory Services Programming"
http://www.directoryprogramming.net
--
Joe,
Thanks for the reply. I'm aware that you can't create processes this way,
but I've seen posts in this ng where they claim you can create a new Thread
that way but I can't get that to work either. Inside the thread the current
WindowsIdentity is still WINDOWS SERVICE.
Can you confirm that creating a new Thread with an impersonated
WindowsIdentity should work? If it does, would creating a new process
inside that thread have the correct WindowsIdentity?
k
> It doesn't work this way. Processes created with the Process class
> inherit the process token, not the impersonated token. The Process class
[quoted text clipped - 52 lines]
>>
>> Keith
Joe Kaplan - 15 Dec 2006 00:29 GMT
Maybe I'm just misremembering and only the ThreadPool does this
automatically now? I'm sure Dominick or someone will correct me.
In any case, if you just spin up a thread with the Thread class, you should
be able to impersonate by passing in the WindowsIdentity in the state for
the thread and then just impersonating it manually. It is a little
annoying, but should work.
Regardless, creating a new Process will always use the process identity
unless you start the process with explicit credentials or perhaps attempt
that pinvoke technique I mentioned.
Joe K.

Signature
Joe Kaplan-MS MVP Directory Services Programming
Co-author of "The .NET Developer's Guide to Directory Services Programming"
http://www.directoryprogramming.net
--
> Joe,
>
[quoted text clipped - 65 lines]
>>>
>>> Keith
Dominick Baier - 15 Dec 2006 07:30 GMT
in .NET 2.0 impersonation tokens are generally propagated to new threads
(regardless of how you create the thread).
That said - Sql Server may behave different (as does ASP.NET see http://www.leastprivilege.com/WhatIsAspnetconfig.aspx)
-----
Dominick Baier (http://www.leastprivilege.com)
> Maybe I'm just misremembering and only the ThreadPool does this
> automatically now? I'm sure Dominick or someone will correct me.
[quoted text clipped - 9 lines]
>
> Joe K.
Dominick Baier - 15 Dec 2006 07:31 GMT
You may also have a look at System.Threading.ExecutionContext...
But be aware that some things are just not allowed/supported in SQL Server...
-----
Dominick Baier (http://www.leastprivilege.com)
> Maybe I'm just misremembering and only the ThreadPool does this
> automatically now? I'm sure Dominick or someone will correct me.
[quoted text clipped - 9 lines]
>
> Joe K.
Keith - 15 Dec 2006 01:28 GMT
Joe,
I found this article and if you substitute SQL Server for IIS/ASP.NET it
gets pretty close:
http://support.microsoft.com/default.aspx?scid=kb;EN-US;889251
Sadly, I can't get this to work either; the DuplicateTokenEx always fails if
I user the SqContext.WindowsIdentity.Token of the login user. I added the
required user rights (Replace a process level token) at the local and domain
level, but DuplicateTokenEx still returns 0 (as does LastError). It does
work if I use CurrentUser() which is WINDOWS SERVICE.
Any ideas how I might be able to find out why the DuplicateTokenEx is
failing?
Keith
> Joe,
>
[quoted text clipped - 65 lines]
>>>
>>> Keith
Joe Kaplan - 15 Dec 2006 02:37 GMT
I don't really have any idea on this one, but GetLastError should work. I'd
suggest trying to use the Marshal.GetLastWin32Error and make sure you call
that right after you call DuplicateTokenEx to ensure that nothing clears
that state. Maybe that will help.
This might be a question you want to try out in the PlatformSDK.Security
newsgroup too.
Good luck!

Signature
Joe Kaplan-MS MVP Directory Services Programming
Co-author of "The .NET Developer's Guide to Directory Services Programming"
http://www.directoryprogramming.net
--
> Joe,
>
[quoted text clipped - 86 lines]
>>>>
>>>> Keith