You shouldn't do that.
Impersonation should only be done a limited amount of time. Historically
for most cases. But you might experience anomalies when creating new threads
or doing other kinds of thread switches (e.g. when calling COM components).
If you want a process to run under a certain identity - start it like that.
> Well, I don't know much about ProecessStartInformation but I'll look
> into it.
> What I have done do far was to create an impersonate class and in the
> load
> routine start the impersonation and in the close routine end
> impersonaton.
> Will this work?
>
> "Dominick Baier" wrote:
>
>> Should this happen "inside" your app - like on the current thread -
>> or do you want to spawn a separate process?
>>
>> for a)
>>
>> - create a token from the credentials (use LogonUser for that) - call
>> WindowsIdentity.Impersonate on that token (put that into a using
>> block)
>>
>> for b)
>>
>> - supply credentials in a ProcessStartInformation
>> - pass the PSI into Process.Start
>> -----
>> Dominick Baier (
http://www.leastprivilege.com)
>> Developing More Secure Microsoft ASP.NET 2.0 Applications
>> (
http://www.microsoft.com/mspress/books/9989.asp)
>>
>>> Hello,
>>>
>>> I have been asked to implement a 'run as' methodology in a .net
>>> application. I have read several threads regarding impersonation but
>>> have questions.
>>>
>>> Here is what I think I need to do....
>>>
>>> I have already a 'setting' that can be maintained off of the tool
>>> menu so that the 'run as' creditentials can be maintained. I encode
>>> and decode the password just in case. Now I want this
>>> 'impersonation' to override current creditentials for the program
>>> while it is running.
>>>
>>> Should this be done in the 'load' and 'close' of the main screen of
>>> the application? Also, I read something about a powerful setting ,
>>> something like ' as part of the operating system'. Is this
>>> neccessary for the original application user or for the
>>> creditentials being used in the impersonation?
>>>
>>> Basically, the staff wants the application to execute in a 'run as'
>>> mode. Can you someone provide some assistance?
>>>
>>> Thank you in advance.
>>>
>>> Dean.
>>>