当前位置:编程学习 > C#/ASP.NET >>

C#中调用DOS命令问题

写了这样一段代码,是想重启资源管理器进程
            Process command = new Process();
            command.StartInfo.UseShellExecute = false;
            command.StartInfo.FileName = "cmd";
            command.StartInfo.RedirectStandardInput = true;
            command.StartInfo.RedirectStandardOutput = true;
            command.StartInfo.CreateNoWindow = true;
            command.Start();
            command.StandardInput.WriteLine("taskkill /im explorer.exe /f"+"\n"+"start c:\\windows\\explorer.exe");
            command.StandardInput.WriteLine("exit");
            command.StandardOutput.ReadToEnd();
            command.Close();

能运行,但是运行完后就卡死了
--------------------编程问答-------------------- 是否你的循环里面没有处理推出? --------------------编程问答-------------------- Mark --------------------编程问答-------------------- 我写的个方法调用的,退出那不整个程序都退出了 --------------------编程问答--------------------
            Process p = new Process();

            p.StartInfo.FileName = "cmd.exe";
            p.StartInfo.Arguments = "/c taskkill /im explorer.exe /f";
            p.StartInfo.UseShellExecute = false;
            p.StartInfo.RedirectStandardInput = true;
            p.StartInfo.RedirectStandardOutput = true;
            p.StartInfo.RedirectStandardError = true;
            p.StartInfo.CreateNoWindow = true;

            p.Start();
            p.StandardInput.WriteLine("exit");

            return;
--------------------编程问答--------------------
                Process p = new Process();                

                p.StartInfo.FileName = "cmd.exe";
                p.StartInfo.Arguments = "/c explorer.exe";
                p.StartInfo.UseShellExecute = false;
                p.StartInfo.RedirectStandardInput = true;
                p.StartInfo.RedirectStandardOutput = true;
                p.StartInfo.RedirectStandardError = true;
                p.StartInfo.CreateNoWindow = true;

                p.Start();
                p.StandardInput.WriteLine("exit");
--------------------编程问答-------------------- 参考微软的贴子:

http://support.microsoft.com/kb/305369 --------------------编程问答-------------------- 我用lz的代码没有死,
可能是因为我没有通过函数调用 --------------------编程问答-------------------- 顶!!! --------------------编程问答-------------------- 楼上的代码可以,谢啦
补充:.NET技术 ,  C#
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,