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

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");

posted @ 2015-03-05 10:23  潋滟碧水醉落花  阅读(1461)  评论(0编辑  收藏  举报