我想用System.Diagnostics.Process運(yùn)行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();這些代碼不起作用。我也嘗試過這個(gè):proc.StandardInput.WriteLine("net use * /delete");proc.StandardInput.WriteLine("Y"); 還是不行我應(yīng)該怎么辦?
1 回答

喵喔喔
TA貢獻(xiàn)1735條經(jīng)驗(yàn) 獲得超5個(gè)贊
net use需要一個(gè)/y標(biāo)志,所以你可以直接傳遞它。你不需要輸入它。您還可以像這樣簡(jiǎn)化代碼:
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 關(guān)注
- 221 瀏覽
添加回答
舉報(bào)
0/150
提交
取消