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

C#自我总结: 运行DOS命令如何隐藏DOS界面

2012-01-23 01:37 926 查看
这也是杀掉桌面进程explorer.exe而不自启的唯一方法,例如:Projects.DOS.cmd("taskkill /f /im explorer.exe"),不信你试一试!利用timer控件可轻易禁用taskmgr.exe。

作者:(⊙_⊙)★燚♂靈惢★空间
出处:http://515847999.qzone.qq.com
CSDN个人主页:http://hi.csdn.net/qq515847999
本文版权归作者和广大编程爱好者共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利……

using System;

using System.Collections.Generic;

using System.Text;

using System.Diagnostics;
namespace Projects

{

    class DOS

    {

        public static string cmd(String command)               //向cmd()传入命令行,传入"exit"则退出cmd.exe。

        {

            Process p = new Process();

            p.StartInfo.FileName = "cmd.exe";

            p.StartInfo.UseShellExecute = false;                  //这里是关键点,不用Shell启动

            p.StartInfo.RedirectStandardInput = true;             //重定向输入

            p.StartInfo.RedirectStandardOutput = true;            //重定向输出

            p.StartInfo.CreateNoWindow = true;                    //不显示窗口

            p.Start();

            p.StandardInput.WriteLine(command);// 向cmd.exe输入command

            //p.WaitForExit();

            p.StandardInput.WriteLine("exit");
            string s = p.StandardOutput.ReadToEnd();// 得到cmd.exe的输出

            p.Close();

            return s;

        }

    }

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  dos c# command string cmd timer