SecureString pass = new SecureString ();
foreach (char c in "yourpassword".ToCharArray())
{
pass.AppendChar(c);
}
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.FileName = Application.StartupPath + "\\cmd.exe";
startInfo.WindowStyle = ProcessWindowStyle.Hidden;
startInfo.CreateNoWindow = true;
startInfo.UseShellExecute = false;
startInfo.Domain = "yourdomain"
startInfo.UserName = "yourusername"
startInfo.Password = pass;
Process.Start(Info);
只需根据需要填写即可。
要提升您必须提示输入 UAC,为此您可以使用
startInfo.Verb = "runas";
或创建一个清单文件,右键单击您的项目 -> 添加项目 -> 清单文件
找到写着的那一行
<requestedExecutionLevel level="asInvoker" uiAccess="false"/>
并将其更改为
<requestedExecutionLevel level="requireAdministrator" uiAccess="false"/>