您的位置:首页 > 编程语言 > C#

【转】C# 后台开启 cmd执行命令

2015-03-05 10:23 260 查看
private void RunCmd(string cmd)
    {
        System.Diagnostics.Process p = new System.Diagnostics.Process();
        p.StartInfo.FileName = "cmd.exe";
        // 关闭Shell的使用
        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(cmd);
        p.StandardInput.WriteLine("exit");
    }

//删除浏览器的缓存和cookie

RunCmd("RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 8");
RunCmd("RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 2");
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: