在.NET中运行外部程序的3种方法

   在win32中有ShellExecute方法可以使我们启动外部的应用程序,在 .NET FrameWork 中我们可以使用Process类来完成类似的功能。 

    Process在System.Diagnostics中,所以别忘了:

      
      
using System.Diagnostics;

    1) 用Process的静态方法Start

      
      
// 启动记事本 Process.Start( " notepad.exe " ); // 启动记事本,并打开temp.txt文件 Process.Start( " notepad.exe " , @" d:/temp.txt " );

    此方法最简单,但功能有限 

    2) 用带有ProcessStartInfo参数的 Start方法

      
      
ProcessStartInfo startInfo = new ProcessStartInfo( " notepad.exe " ); startInfo.Arguments = @" d:/temp.txt " ; // 启动时最小化 startInfo.WindowStyle = ProcessWindowStyle.Minimized; startInfo.Verb = " open " ; Process.Start(startInfo);

    3)实例化Process类

      
      
Process process = new Process(); process.StartInfo.FileName = " notepad.exe " ; process.StartInfo.Verb = " open " ; process.StartInfo.WindowStyle = ProcessWindowStyle.Minimized; process.StartInfo.Arguments = @" d:/temp.txt " ; process.Start();


    第2种方法和第3种方法差不多,他们的可选的功能就比较多了。 

  TrackBack:   http://tech.it168.com/n/2006-11-14/200611141412978.shtml

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值