I need to run this as an administrator
string cname = Environment.UserDomainName + "\\" + Environment.UserName;
string resetTrust = "netdom /resetpwd /s:server01 /ud:" + cname + "/pd:" + textBoxPassword.Text.Trim();
String output = ExecuteCommandAsAdmin(resetTrust);
MessageBox.Show(output);
Here is the method ExecuteCommandAsAdmin
public static string ExecuteCommandAsAdmin(string command)
{
string cname = Environment.UserDomainName + "\\" + Environment.UserName;
ProcessStartInfo procStartInfo = new ProcessStartInfo()
{
RedirectStandardError = true,
RedirectStandardOutput = true,
UseShellExecute = false,
CreateNoWindow = true,
FileName = "runas.exe",
Arguments = "/user:" + cname + "\"cmd /K " + command + "\""
};
using (Process proc = new Process())
{
proc.StartInfo = procStartInfo;
proc.Start();
string output = proc.StandardOutput.ReadToEnd();
if (string.IsNullOrEmpty(output))
output = proc.StandardError.ReadToEnd();
return output;
}
}
If you know a better way to do this, please let me know. I am not storing the password. Just passing it so it can be executed. If the wrong person enters the wrong password, nothing happens since they aren't an Admin.
Thank You