我想编写一个具有以下功能的程序:用户执行程序(C# 中的控制台应用程序),键入程序名称,然后按 Enter 键,程序应该初始化。
问问题
61 次
3 回答
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();
}
}
于 2012-11-27T16:35:36.987 回答
0
This feature is built into the core of .NET, no external library required:
http://msdn.microsoft.com/en-us/library/system.diagnostics.process.start.aspx
于 2012-11-27T16:32:02.337 回答
0
Have a look at the Process
[MSDN] class. That should get you started, and if you have any trouble, post another question.
Here's the example from the linked MSDN documentation:
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);
}
}
}
}
于 2012-11-27T16:32:34.880 回答