就比如说shundow.exe,我在cmd窗口输入 shutdown.exe /?可以看到它的帮助信息,里面包含了它支持哪些参数,比如:
 
Usage: shutdown [/i | /l | /s | /r | /g | /a | /p | /h | /e] [/f]
    [/m \\computer][/t xxx][/d [p|u:]xx:yy [/c "comment"]]   No args    Display help. This is the same as typing /?.
    /?         Display help. This is the same as not typing any options.
    /i         Display the graphical user interface (GUI).
               This must be the first option.
    /l         Log off. This cannot be used with /m or /d options.
    /s         Shutdown the computer.
    /r         Shutdown and restart the computer.
    /g         Shutdown and restart the computer. After the system is
               rebooted, restart any registered applications.。怎样在代码里头得到上面这些内容呢?
谢谢

解决方案 »

  1.   

    呵呵 一个笨办法,把这个输出到一个temp文件中,然后读取
    比如system("shutdown.exe /?>c:\\$$temp.txt");
     
      

  2.   

     System.Diagnostics.Process _ProcessCommand = new System.Diagnostics.Process();
                _ProcessCommand.StartInfo.FileName = "Cmd.exe";
                _ProcessCommand.StartInfo.Arguments = "/C DIR /?";
                _ProcessCommand.StartInfo.UseShellExecute = false;
                _ProcessCommand.StartInfo.CreateNoWindow = true;
                _ProcessCommand.StartInfo.RedirectStandardOutput = true;            
                _ProcessCommand.Start();
                _ProcessCommand.WaitForExit();            string _Text = _ProcessCommand.StandardOutput.ReadToEnd();
      

  3.   

    private void button1_Click(object sender, EventArgs e)
    {
        Execute("shutdown",0);
    }
     public static string Execute(string dosCommand, int outtime)
            {
                string output = "";
                if (dosCommand != null && dosCommand != "")
                {
                    Process process = new Process();//创建进程对象
                    ProcessStartInfo startinfo = new ProcessStartInfo();//创建进程时使用的一组值,如下面的属性
                    startinfo.FileName = "cmd.exe";//设定需要执行的命令程序
                    //以下是隐藏cmd窗口的方法
                    startinfo.Arguments = "/c" + dosCommand;//设定参数,要输入到命令程序的字符,其中"/c"表示执行完命令后马上退出
                    startinfo.UseShellExecute = false;//不使用系统外壳程序启动
                    startinfo.RedirectStandardInput = false;//不重定向输入
                    startinfo.RedirectStandardOutput = true;//重定向输出,而不是默认的显示在dos控制台上
                    startinfo.CreateNoWindow = true;//不创建窗口
                    process.StartInfo = startinfo;                try
                    {
                        if (process.Start())//开始进程
                        {
                            if (outtime == 0)
                            { process.WaitForExit(); }
                            else
                            { process.WaitForExit(outtime); }
                            output = process.StandardOutput.ReadToEnd();//读取进程的输出
                        }
                    }
                    catch
                    {                }
                    finally
                    {
                        if (process != null)
                        { process.Close(); }
                    }
                }
                return output;
            }