How to run c# application with admin creds?

后端 未结 7 781
旧时难觅i
旧时难觅i 2020-12-19 08:03

I wrote a C# application that unlocks users when they are locked out of their account (Active Directory). The application searches for users in a specific OU and will list t

7条回答
  •  失恋的感觉
    2020-12-19 08:27

    You don't have to use a windows service to do something as someone else. You can use impersonation to login as another user to do the actual switch. Here’s an example I found that uses the windows dll "advapi32.dll" to login.

    Grab the sample code off the bottom of the page. I didn’t want to just copy his code here.

    http://csharptuning.blogspot.com/2007/06/impersonation-in-c.html

    One cavet with Impersonation though is that the computer doing the impersonation needs to be on the same domain as the user that your impersonating.

提交回复
热议问题