我想用System.Diagnostics.Process運行cmd命令:“net use * /delete”,但該命令需要輸入“Y”或“N”。這是我的代碼:Process proc = new Process();proc.StartInfo.FileName = "cmd.exe";proc.StartInfo.UseShellExecute = false;proc.StartInfo.RedirectStandardInput = true;proc.StartInfo.RedirectStandardOutput = true;proc.StartInfo.RedirectStandardError = true;proc.StartInfo.CreateNoWindow = true;string dosLine = "/C echo y | net use * /delete";proc.StartInfo.Arguments = dosLine;proc.Start();這些代碼不起作用。我也嘗試過這個:proc.StandardInput.WriteLine("net use * /delete");proc.StandardInput.WriteLine("Y"); 還是不行我應該怎么辦?
1 回答

喵喔喔
TA貢獻1735條經驗 獲得超5個贊
net use需要一個/y標志,所以你可以直接傳遞它。你不需要輸入它。您還可以像這樣簡化代碼:
Process proc = new Process();
proc.StartInfo.FileName = "net";
proc.StartInfo.Arguments = "use * /delete /y";
proc.StartInfo.UseShellExecute = true;
proc.StartInfo.RedirectStandardOutput = true;
proc.StartInfo.RedirectStandardError = true;
proc.StartInfo.CreateNoWindow = true;
proc.Start();
- 1 回答
- 0 關注
- 204 瀏覽
添加回答
舉報
0/150
提交
取消