zoukankan      html  css  js  c++  java
  • 创建一个进程并调用(.net)

            最近有一个项目需求,需要调用一个exe,就上网查询了一下,顺利的完成了工作,感觉虽然简单,但挺有意思,就记录一下。

        一,创建一个进程

              1,代码视图(控制台程序)

                  

              2,代码        

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Diagnostics;
    
    namespace KillProcess
    {
        class Program
        {
            static void Main(string[] args)
            {
                if (args == null || args.Length == 0)
                    return;
                if (args[0].Equals("help") || args[0].Equals("?")||args[0].Equals("-help"))
                {
                    Console.WriteLine(" 使用该进程,可以杀掉进程 命令形式如下:");
                    Console.WriteLine("  KillProcess [-ProcessName]");
                    Console.WriteLine("  ProcessName 要杀掉的进程的名称");
                }
                Process[] ps = null;
                foreach (String pName in args)
                {
                    ps = Process.GetProcessesByName(pName);
                    if (ps != null && ps.Length > 0)
                    {
                        foreach (Process p in ps)
                        {
                            p.Kill();
                        }
                    }
                }
            }
        }
    }
    View Code

        二,用CMD调用

              

        三,用程序调用

              1.代码视图

                  

              2.代码

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Diagnostics;
    
    namespace InvokeProcess
    {
        class Program
        {
            static void Main(string[] args)
            {
    
                Process process = new Process();
    
                process.StartInfo.WorkingDirectory = @"E:AAProcessTestKillProcessinDebug";
                process.StartInfo.Arguments = "notepad";
                process.StartInfo.FileName = "KillProcess";
    
                process.Start();
    
                process.WaitForExit();
    
    
            }
        }
    }
    View Code
  • 相关阅读:
    HDU 1677
    HDU 1672 Cuckoo Hashing
    HDU 2586 + HDU 4912 最近公共祖先
    最大流 Dinic + Sap 模板
    网络流算法小结(转)
    Malformed network data报错解决方法
    js window.open 参数设置
    java图片高质量缩放类
    struts2 I18n问题 国际化
    java.lang.Exception: Socket bind failed 服务器端口冲突-->修改端口
  • 原文地址:https://www.cnblogs.com/liangjie/p/3807140.html
Copyright © 2011-2022 走看看