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
  • 相关阅读:
    微人事项目-mybatis-持久层
    通过外键连接多个表
    springioc
    Redis 消息中间件 ServiceStack.Redis 轻量级
    深度数据对接 链接服务器 数据传输
    sqlserver 抓取所有执行语句 SQL语句分析 死锁 抓取
    sqlserver 索引优化 CPU占用过高 执行分析 服务器检查
    sql server 远程备份 bak 删除
    冒泡排序
    多线程 异步 beginInvoke EndInvoke 使用
  • 原文地址:https://www.cnblogs.com/liangjie/p/3807140.html
Copyright © 2011-2022 走看看