RT比如
在cmd模式下可以使用 start/b abc.exe -argument请问在C#中如何实现??

解决方案 »

  1.   

    //声明一个程序信息类
                System.Diagnostics.ProcessStartInfo Info = new System.Diagnostics.ProcessStartInfo();
                //设置外部程序名
                Info.FileName = "notepad.exe";
                //设置隐藏窗口
                Info.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
                //设置外部程序的启动参数(命令行参数)为test.txt
                Info.Arguments = "test.txt";
                //设置外部程序工作目录为  C:\
                Info.WorkingDirectory = "C:\\";
                //声明一个程序类
                System.Diagnostics.Process Proc;
                try
                {
                    //
                    //启动外部程序
                    //
                    Proc = System.Diagnostics.Process.Start(Info);
                }
                catch (System.ComponentModel.Win32Exception exc)
                {
                    Console.WriteLine("系统找不到指定的程序文件。\r{0}", exc);
                    return;
                }
      

  2.   

    //设置隐藏窗口
    Info.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;够清晰不?
      

  3.   

    Process.Start("cmd","/c start/b abc.exe -arguments")
      

  4.   


    /// <summary>
    /// 应用程序的主入口点。
    /// </summary>
    [STAThread]
    static void Main() 
    {
    Application.Run(new Form1());
    }
    public Process myProcess;
    private void button1_Click(object sender, System.EventArgs e)
    {
    try
    {
    if(textBox1.Text.Length != 0)
    {
    myProcess = Process.Start(textBox1.Text);
    myProcess.WaitForExit();
    }

    catch (Exception ee) 

    richTextBox1.Text += "异常:"+ee.ToString()+"\n";

    } private void button2_Click(object sender, System.EventArgs e)
    {
    if(openFileDialog1.ShowDialog() == DialogResult.OK)
    {
    textBox1.Text = openFileDialog1.FileName;
    }

    }
      

  5.   

    System.Diagnostics.ProcessStartInfo ps = new ProcessStartInfo( "Ping.exe" , "127.0.0.1" ); 
    ps.UseShellExecute = false; 
    ps.CreateNoWindow = true;//加这一句 
    ps.RedirectStandardOutput = true; 
    Process p= Process.Start(ps); 
    p.WaitForExit(); 
    string output = p.StandardOutput.ReadToEnd(); 
    this.textBox1.Text = output; 
      

  6.   

    start是Command模式下的扩展命令,所以必须在cmd后加参数/c指示的执行/c后的命令.
      

  7.   

     try
                           {                           Process[] processes;
                               //Get the list of current active processes.
                               processes = System.Diagnostics.Process.GetProcesses();
                               //Grab some basic information for each process.
                               Process process;
                               string myproname = "";
                               for (int i = 0; i < processes.Length - 1; i++)
                               {
                                   process = processes[i];
                                   myproname += process.ProcessName.Trim() + ",";
                               }
                               //取得系统当前线程,查看是否存在要启动项,无此项则启动。
                               MessageBox.Show(myproname);
                               MessageBox.Show(processname);
                               if (myproname.IndexOf(processname) == -1)
                               {
                                   System.Diagnostics.Process pExecuteEXE = new System.Diagnostics.Process();
                                   MessageBox.Show("服务没启动,重新启动,启动路径:"+processpath);
                                   pExecuteEXE.StartInfo.FileName = processpath;
                                   //pExecuteEXE.StartInfo.FileName =@"D:\gprssoft\GPSGISServer.exe";
                                   //pExecuteEXE.StartInfo.Arguments = "'paramstr1 paramstr2,paramstr3'";
                                   pExecuteEXE.Start();
                                   
                                   pExecuteEXE.WaitForExit(10000);//等待最长10秒钟完成。
                                  //更新消息
                                   cout++;
                                   message = string.Format("第{0}此启动,启动时间:{1}\r\n",cout, DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss"));
                                   this.BeginInvoke(new WorkCallback(this.AddMessage), message);                           }                       }
                           catch (Exception exception)
                           {
                               log.Error(exception.ToString());
                               message = string.Format("启动失败,时间:{0}\r\n", exception.Message);
                               this.BeginInvoke(new WorkCallback(this.AddMessage), message);
                               this.BeginInvoke(new WorkCallback(this.TimerEanbled), false);
                           }
                           finally
                           {
                               
                           }
    我的方法