I wrote a simple Windows Forms program in C#. I want to be able to input a windows user name and password and when I click a login button to run code run as the user I’ve entered as input.
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You can use the WindowsIdentity.Impersonate method to achieve this. This method allows code to impersonate a different Windows user. Here is a link for more information on this method with a good sample:
http://msdn.microsoft.com/en-us/library/system.security.principal.windowsidentity.impersonate.aspx
Complete example: