zoukankan      html  css  js  c++  java
  • 在.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种方法差不多,他们的可选的功能就比较多了。

     
  • 相关阅读:
    vue中 key 值的作用
    v-on可以监听多个方法吗?
    vue常用的修饰符
    v-if和v-show的区别
    Vue和其他框架的区别
    Vue面试题总结——目录
    vue是一个渐进式的框架,我是这么理解的
    原生JS封装创建多级菜单函数
    如何使用mongodb(建立原型,连接数据库)
    Hive 的安装与配置
  • 原文地址:https://www.cnblogs.com/chenzhao/p/2082082.html
Copyright © 2011-2022 走看看