建立一個進程並調用(.net)

來源:互聯網
上載者:User

標籤:style   class   blog   code   http   tar   

        最近有一個項目需求,需要調用一個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:\AA\ProcessTest\KillProcess\bin\Debug\";            process.StartInfo.Arguments = "notepad";            process.StartInfo.FileName = "KillProcess";            process.Start();            process.WaitForExit();        }    }}
View Code

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.