我正在尝试运行几行命令以尝试使工作流程自动化。我已经在网上进行了一些研究,以了解我需要做什么。但是该文件不受影响。当我通过admin命令提示符运行同一命令时,该命令有效。
命令: 回声127.0.0.1 webedit.egnyte.com >>“ C:\ Windows \ System32 \ drivers \ etc \ hosts”
“%ProgramFiles(x86)%\ Egnyte Connect \ EgnyteDrive.exe”-命令添加-l Egnyte -d seagen -sso use-sso -t U -c connect_immediately
我已将清单更改为“ requireAdministrator”和“ highestAvailable”。但是,该文件仍然没有更改。
private void Button1_Click(object sender, EventArgs e)
{
string command1 = "echo 127.0.0.1 webedit.egnyte.com >> \"C:\\Windows\\System32\\drivers\\etc\\hosts\"";
Console.WriteLine("Starting Command 1: " + command1);
Process process = new Process();
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.WindowStyle = ProcessWindowStyle.Hidden;
startInfo.FileName = "cmd.exe";
startInfo.Arguments = command1;
startInfo.UseShellExecute = true;
startInfo.Verb = "runas";
process.StartInfo = startInfo;
process.Start();
Console.WriteLine("Completed Command 1 ");
}
文件“主机”应该在其中添加一行。