我正在尝试使用以下C#代码运行Windows命令:
var quantity = parseFloat($(this).closest("tr").find("input.qtt:text").val());
但是它不允许我运行Process cmd = new Process();
cmd.StartInfo.FileName = "cmd.exe";
cmd.StartInfo.RedirectStandardInput = true;
cmd.StartInfo.RedirectStandardOutput = true;
cmd.StartInfo.CreateNoWindow = false;
cmd.StartInfo.UseShellExecute = false;
cmd.Start();
cmd.StandardInput.WriteLine("/C @shift /0");
cmd.StandardInput.WriteLine("/C @echo off");
cmd.StandardInput.WriteLine("/C color 04");
cmd.StandardInput.WriteLine("/C title Loop Anti-Ban (Ignore Errors) (RGB)");
cmd.StandardInput.WriteLine("/C :a");
cmd.StandardInput.WriteLine("/C reg delete "HKEY_CURRENT_USER\Software\Epic Games\Unreal Engine\Identifiers" /f");
cmd.StandardInput.Flush();
cmd.StandardInput.Close();
cmd.WaitForExit();
Console.WriteLine(cmd.StandardOutput.ReadToEnd());
不知道为什么...(另一张图片要清楚)
答案 0 :(得分:3)
您需要像这样"
那样在字符串中转义\"
,并且路径中的\
也应这样\\
进行转义:
cmd.StandardInput.WriteLine("/C reg delete \"HKEY_CURRENT_USER\\Software\\Epic Games\\Unreal Engine\\Identifiers\\" /f");