.net框架中的哪个库可用于执行程序?

时间:2012-11-27 16:30:23

标签: c#

我想编写一个具有以下功能的程序: 用户执行程序(C#中的控制台应用程序),键入程序名称,然后按Enter键,程序应初始化。

3 个答案:

答案 0 :(得分:0)

此功能内置于.NET的核心,无需外部库:

http://msdn.microsoft.com/en-us/library/system.diagnostics.process.start.aspx

答案 1 :(得分:0)

查看Process [MSDN] 类。这应该让你开始,如果你有任何麻烦,发布另一个问题。

以下是链接的MSDN文档中的示例:

using System;
using System.Diagnostics;
using System.ComponentModel;

namespace MyProcessSample
{
    class MyProcess
    {
        public static void Main()
        {
            Process myProcess = new Process();

            try
            {
                myProcess.StartInfo.UseShellExecute = false;

                // You can start any process.
                // HelloWorld is a do-nothing example.
                myProcess.StartInfo.FileName = "C:\\HelloWorld.exe";
                myProcess.StartInfo.CreateNoWindow = true;
                myProcess.Start();

                // This code assumes the process you are starting will 
                // terminate itself.  
                //
                // Given that is is started without a window so you cannot 
                // terminate it on the desktop, it must terminate itself 
                // or you can do it programmatically from this application 
                // using the Kill method.
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }
    }
}

答案 2 :(得分:0)

这一次,我会给你代码。如果你想让你的发射器更复杂,那部分由你决定。

class Program
{
    public static void Main(string[] args)
    {
        Process process = new Process();
        process.StartInfo.FileName = args[0];
        process.StartInfo.UseShellExecute = false;
        process.StartInfo.CreateNoWindow = true;
        process.Start();
    }
}