Process proc = new Process();
proc.StartInfo.FileName = @"D:\Program Files\Foxmail\Foxmail.exe";
//可以用绝对路径
proc.StartInfo.Arguments = "";
proc.Start();

注意:使用 Process 类之前 要先添加命名空间

using System.Diagnostics;

辅车相依,唇亡齿寒。纵使晴明无雨色,入云深处亦沾衣。欲渡黄河冰塞川,将登太行雪满山。此曲只应天上有,人间那得几回闻。羁鸟恋旧林,池鱼思故渊。C# 启动外部程序的几种方法:
1. 启动外部程序,不等待其退出。
2. 启动外部程序,等待其退出。
3. 启动外部程序,无限等待其退出。
4. 启动外部程序,通过事件监视其退出。

// using System.Diagnostics;
private string appName = "calc.exe";

/// <summary>
/// 1. 启动外部程序,不等待其退出
/// </summary>
private void button1_Click(object sender, EventArgs e)
{
  Process.Start(appName);
  MessageBox.Show(String.Format("外部程序 {0} 启动完成!", this.appName), this.Text,
  MessageBoxButtons.OK, MessageBoxIcon.Information);
}

/// <summary>
/// 2. 启动外部程序,等待其退出
/// </summary>
private void button2_Click(object sender, EventArgs e)
{
  try
  {
  Process proc = Process.Start(appName);
  if (proc != null)
  {
  proc.WaitForExit(3000);
  if (proc.HasExited)
  MessageBox.Show(String.Format("外部程序 {0} 已经退出!", this.appName), this.Text,
  MessageBoxButtons.OK, MessageBoxIcon.Information);
  else
  {
  // 如果外部程序没有结束运行则强行终止之。
  proc.Kill();
  MessageBox.Show(String.Format("外部程序 {0} 被强行终止!", this.appName), this.Text,
  MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
  }
}
}
  catch (ArgumentException ex)
  {
  MessageBox.Show(ex.Message, this.Text,
  MessageBoxButtons.OK, MessageBoxIcon.Error);
  }
  }

/// <summary>
/// 3. 启动外部程序,无限等待其退出
/// </summary>
private void button3_Click(object sender, EventArgs e)
{
try
{
Process proc = Process.Start(appName);
if (proc != null)
{
proc.WaitForExit();
MessageBox.Show(String.Format("外部程序 {0} 已经退出!", this.appName), this.Text,
MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
catch (ArgumentException ex)
{
MessageBox.Show(ex.Message, this.Text,
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}

/// <summary>
/// 4. 启动外部程序,通过事件监视其退出
/// </summary>
private void button4_Click(object sender, EventArgs e)
{
try
{
// 启动外部程序
Process proc = Process.Start(appName);
if (proc != null)
{
// 监视进程退出
proc.EnableRaisingEvents = true;
// 指定退出事件方法
proc.Exited += new EventHandler(proc_Exited);
}
}
catch (ArgumentException ex)
{
MessageBox.Show(ex.Message, this.Text,
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}

/// <summary>
/// 外部程序退出事件
/// </summary>
void proc_Exited(object sender, EventArgs e)
{
MessageBox.Show(String.Format("外部程序 {0} 已经退出!", this.appName), this.Text,
MessageBoxButtons.OK, MessageBoxIcon.Information);
}

用C#调用CMD.exe,执行DOS命令,编码FLV

Process p = new Process();
p.StartInfo.FileName = "cmd.exe";
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardInput = true;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardError = true;
p.StartInfo.CreateNoWindow = true;
p.Start();
string strOutput=null;
// p.StandardInput.WriteLine("cd D:\\flv\\mplayer");
// p.StandardInput.WriteLine("cd d:");
p.StandardInput.WriteLine(string.Format("D:\\flv\\mplayer\\mencoder \"c:\\vs.wmv\" -o \"c:\\output.flv\" -of lavf -lavfopts i_certify_that_my_video_stream_does_not_use_b_frames -oac mp3lame -lameopts abr:br=56 -ovc lavc -lavcopts vcodec=flv:vbitrate={0}:mbd=2:mv0:trell:v4mv:cbp:last_pred=3:dia=4:cmp=6:vb_strategy=1 -vf scale=512:-3 -ofps 12 -srate 22050",200));

p.StandardInput.WriteLine("exit");
strOutput = p.StandardOutput.ReadToEnd();
Console.WriteLine(strOutput);
p.WaitForExit();
p.Close();

记得同时要导入:using System.Diagnostics;命名空间。祝你好运
亦余心之所善兮,虽九死其犹未悔。夜阑卧听风吹雨,铁马冰河入梦来。临渊羡鱼,不如退而结网。醉卧沙场君莫笑,古来征战几人回!

.Net操作.exe文件的更多相关文章

  1. 在C#中调用EXE文件

    1. 如果exe文件的返回值是int类型,标识操作执行的结果是否成功,例如: class Program { static int Main(string[] args) { return args. ...

  2. WPF 将DLL嵌入EXE文件(安装包)

    网上很多例子,各种套路,就是没有测试过. WPF 将DLL嵌入EXE文件的套路是这样的 1.将要引用的dll源文件添加到wpf 项目中,dll 的属性->生成操作为[嵌入的资源]. 2.监听  ...

  3. [原创]Matlab之GUI生成EXE文件

    近期因为项目需要,简化流程,写了一些Matlab程序,并配备上了GUI界面使其简单易用.然后问题来了,可移植性.使用Matlab生成EXE文件(可以封装很多的function),然后在一台安装有Mat ...

  4. c#启动EXE文件(简单的)

    在程序执行中会遇到启动本软件的exe问,或者启用其它的exe文件,已达到执行某些操作的作用.下面是两种最常见的启动exe文件. 1.调用系统dll使用其提供的方法. 引用的dll, [DllImpor ...

  5. 关于win7系统中所有exe文件都被以word方式打开的解决方法

    手残一刻,电脑桌面所有的软件快捷方式都变成了word的打开方式,鼠标右键选中某exe文件也没打开方式那个选项, 第一次尝试: 在控制面板——默认程序中修改默认打开方式,但是没有找到解决方法

  6. 如何用DELPHI编程修改外部EXE文件的版本信

    右击里面有修改 点开直接修改就可以了吧. DELPHI 里程序的版本信息怎么是灰色的,无法更改 耐心读以下说明,应该能解决你的问题,如果不能解决,请Hi我~ 如何给自己的dll文件添加版本信息呢? 首 ...

  7. VC6.0生成的exe文件图标

    以下是我网上收到的方法 我都试过 成功不了 具体说下我遇到的问题 VC6.0生成的exe文件图标是用Icon下几个图标中value值最小的,顺序为IDR_MAINFRAME.IDR_ICONTETYP ...

  8. JDK/bin目录下的不同exe文件的用途(转)

    新安装完JDk 大家是否发现安装目录的bin文件夹有很多exe文件 下面就为大家讲解不同exe文件的用途 javac:Java编译器,将Java源代码换成字节代 java:Java解释器,直接从类文件 ...

  9. C#调用Exe文件的方法及如何判断程序调用的exe已结束

    很简单的代码就可以实现C#调用EXE文件,如下: 引入using System.Diagnostics; 调用代码: Process.Start(exe文件名); 或直接 System.Diagnos ...

随机推荐

  1. C# WinForm动态添加MSChart控件

    添加mschart.dll动态链接库 添加引用 System.Windows.Forms.DataVisualization     MSChart控件作为方便的用户数据展示控件,可以方便的使用控件提 ...

  2. html5新增全局属性

    data-* 如:data-type,data-role等 hidden  <div hidden></div> 隐藏该div spellcheck <textarea ...

  3. Fatal error: Call to a member function bind_param() on a non-object in

    今天在练习 mysql是出现错误:   Fatal error: Call to a member function bind_param() on a non-object in 解决步骤: 1. ...

  4. Openstack的mysql数据多主galera的错误

    登录openstack的在dashboard,提示说权限验证错误,有2种情况: 1. 密码被人改了. 2. 系统发生了问题. 密码确认没人改,所以查看/var/log/keystone-all.log ...

  5. Openstack的HA解决方案【haproxy和keepalived】

    1. 安装haproxy,keepalived, httpd,3台机器一致. yum install haproxy keepalived httpd -y 2. 修改httpd的默认页面. 在/va ...

  6. Delphi 中将一些 Dll等生成资源文件打包成一个独立的EXE程序方法步骤

    资源文件一般为扩展名为res的文件,其自带的资源编译工具BRCC32.EXE(位于/Delphi/BIN目录下) 1.编写rc脚本文本 用记事本或其它文本编辑器编写一个扩展名为rc的文件,格式分别为在 ...

  7. 【python】__future__模块

    转自:http://www.jb51.net/article/65030.htm Python的每个新版本都会增加一些新的功能,或者对原来的功能作一些改动.有些改动是不兼容旧版本的,也就是在当前版本运 ...

  8. JSP页面跳转方式

    JSP页面跳转方式 1.利用按钮+javascript进行跳转 <input type="button" name="button2" value=&qu ...

  9. ubuntu apache开启重写模块

    http://www.iblue.cc/2011/09/ubuntu-apache%E5%BC%80%E5%90%AF%E9%87%8D%E5%86%99%E6%A8%A1%E5%9D%97/ Ubu ...

  10. 5.1JavaScript精华

    9.使用Promises Promises,是Javascript表现item的一种方式.它执行异步工作,在未来的某个时间点完成.遇到最多的promises,是使用Ajax请求.浏览器在后台发起HTT ...