所以我找到了
System.Diagnostics.Process.Start()
但是,然后我想关闭启动它的应用程序(我需要启动器连接到服务器,启动游戏并关闭它自己)所以它不起作用。 我的应用:
public partial class MainWindow : Window
{
Process.Start("xnagame.exe", "12345678");
this.Close();
}
答案 0 :(得分:1)
为进程命名,以便您有一个句柄来关闭它。并非所有流程都能正常关闭。
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);
}
答案 1 :(得分:0)
使用Process.Start(ProcessStartInfo)
重载,并将UseShellExecute
属性设置为true
。