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. lower power的IP设计

    在IP的实现过程中,考虑lower power部分进行设计: 1)Partition the design来满足lower power的一些strategies,尤其是power gating和clo ...

  2. com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException

    Exception in thread "main" com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You ...

  3. 【linux】终端直接执行py文件,不需要python命令

    先将终端所在路径切换到python脚本文件的目录下然后给脚本文件运行权限,一般755就OK,如果完全是自己的私人电脑,也不做服务器什么的,给777的权限问题也不大(具体权限含义参考chmod指令的介绍 ...

  4. UIViewController启动过程

    流程:判断是否view属性为nil,如果为空,调用loadView方法,如果重写了loadView方法,那么从代码创建普通视图,如果没有重写并且有storyBoard或者xib文件,那么从storyB ...

  5. mysql命令行操作

    显示数据库    show databases;当前数据库 select database(); 显示表    show tables;更改表名称    alter table 原表名 rename ...

  6. 【python cookbook】【数据结构与算法】8.与字典有关的计算问题

    问题:在字典上对数据执行各式各样的计算(比如求最小值.最大值.排序). 解决方案:利用zip()将字典的键-值对“反转”为值-键对序列. 例如:如下字典存放的股票名称和对应的价格: >>& ...

  7. input放在a标签里面不能选择input里面的文本,IE9点击失效

    input放在a标签里面不能选择input里面的文本,IE9点击失效 在IE浏览器中<input type="text" value="test" /&g ...

  8. Linux 进程状态【转】

    转自:http://www.cnblogs.com/itech/p/3208261.html 来自: http://blog.csdn.net/tianlesoftware/article/detai ...

  9. Linux设备驱动之semaphore机制【转】

    转自:http://blog.csdn.net/xiao229404041/article/details/7031776 Linux设备驱动之semaphore机制在Linux系统中,信号号是一种重 ...

  10. 错误代码:ERR_UNSAFE_PORT

    修改下应用的端口为7788就好了:http://localhost:7788/taiping-sol-insu-vehicle/vehicleEntrance.action. 这个主要是chrome的 ...