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
  • 相关阅读:
    抽象类与抽象方法
    PCB设计铜铂厚度、线宽和电流关系
    单层或双层板(PCB)减少环路面积
    电源模块布局考虑因素总结
    传感器信号处理电路
    共模电压和差模电压
    采样电阻选型
    电源防反接保护电路
    MOSFET驱动电路
    自相关与偏自相关
  • 原文地址:https://www.cnblogs.com/liangjie/p/3807140.html
Copyright © 2011-2022 走看看