在.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种方法差不多,他们的可选的功能就比较多了。


posted @   柒零壹  阅读(673)  评论(0编辑  收藏  举报
编辑推荐:
· C++代码改造为UTF-8编码问题的总结
· DeepSeek 解答了困扰我五年的技术问题
· 为什么说在企业级应用开发中,后端往往是效率杀手?
· 用 C# 插值字符串处理器写一个 sscanf
· Java 中堆内存和栈内存上的数据分布和特点
阅读排行:
· 为DeepSeek添加本地知识库
· .NET程序员AI开发基座:Microsoft.Extensions.AI
· 精选4款基于.NET开源、功能强大的通讯调试工具
· 数据不出内网:基于Ollama+OneAPI构建企业专属DeepSeek智能中台
· 大模型工具KTransformer的安装
点击右上角即可分享
微信分享提示