How to run c# application with admin creds?

后端 未结 7 806
旧时难觅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:16

    This code will allow you to call another executable and run it is an administrator.

    try
    {
       path = path_to_your_executable;
    
       ProcessStartInfo myProcess = new ProcessStartInfo(path);
       myProcess.Domain = domain;
       myProcess.UserName = username;
       myProcess.Password = password;
       myProcess.UseShellExecute = false;
    
       Process.Start(myProcess);
    }
    catch (Exception myException)
    {
       // error handling
    }
    

    Not exactly what you're looking for but it is a possible solution.

提交回复
热议问题