所以我发现
System.Diagnostics.Process.Start()
但是,然后我想关闭启动它的应用程序(我需要启动器连接到服务器,启动游戏并自行关闭)所以它不起作用。我的应用程序:
public partial class MainWindow : Window
{
Process.Start("xnagame.exe", "12345678");
this.Close();
}
命名进程,以便您有一个句柄来关闭它。并非所有进程都能正常关闭。
try
{
Process myProcess;
myProcess = Process.Start("Notepad.exe");
// Display physical memory usage 5 times at intervals of 2 seconds.
for (int i = 0;i < 5; i++)
{
if (!myProcess.HasExited)
{
// Discard cached information about the process.
myProcess.Refresh();
// Print working set to console.
Console.WriteLine("Physical Memory Usage: "
+ myProcess.WorkingSet.ToString());
// Wait 2 seconds.
Thread.Sleep(2000);
}
else {
break;
}
}
// Close process by sending a close message to its main window.
myProcess.CloseMainWindow();
// Free resources associated with process.
myProcess.Close();
}
catch(Exception e)
{
Console.WriteLine("The following exception was raised: ");
Console.WriteLine(e.Message);
}
使用Process.Start(ProcessStartInfo)
重载,并将UseShellExecute
属性设置为true
。