Impersonation with C#

Hi,

I am using .NET 1.1 on win 2KProfessional.

I am struck with a big problem.
I need sme help.

I am doing the test automation.

Once I execute my exe I am adding One person as administrator(AAA) to a
my local system and restart my machine.

I login in to AAA and Installing one package into this User.
In this case I need to degrade the same administrator(AAA) to normal
User.

I again restart my machine..

In this scenario I logoin into normal user and UnInstalling the same
package.(Of course the package is not UnInstalled).

In this I need to Upgrade the same normal user(AAA) into Administrator.

How to do the Impersonation with C# or even with C# APIs.

I call those APIs from the C#.

Please help me from this.

Thanks in advance.

regards



Answer this question

Impersonation with C#

  • Mark Donnelly

    P.S.:

    The reason why I wouldn't recommend going through with your original idea is simple: you're most likely stuck with hardcoding administrative credential if you want to process all this from your C# code. Which means that you'd really need to do much more work to encrypt this credential than it is probably worth...


  • bk01

    You're running in security risks here... (and not just one of them).

    I understand that you're trying to do "unattended installation" of your (or someone else's) program, is this right In which case have you considered two alternatives:

    1. install with elevated priviledge (which may not always work, depending on how stict are your company's Policy settings) - see Windows Installer documentation.
    2. TEMPORARILY modify "Recovery console: Allow automatic administrative logon" policy setting for the time of installation (reboot the system). At the end of installation don't forget to disable this setting (or users will operate with full-blown priviledge and... will loose access to Domain resources as they would operate under local account).

    Whichever you choose (either one of the above may work) it is probably important to think about how to temporarily disable keyboard and mouse when installation begins so that users are not able to take-over the console during the installation (especially if you use the second option).

    Hope this helps a bit...

    Gregg.


  • Impersonation with C#