简体   繁体   English

Process.Start()并尝试启动游戏

[英]Process.Start() And Trying to launch a game

I'm trying launch an application using c#, and have been experimentiing with the following line, if I run this from a cmd prompt it's ok but when running in my forms app it fails. 我正在尝试使用c#启动应用程序,并且一直在尝试以下行,如果我从cmd提示符下运行此程序就可以了,但是在窗体应用程序中运行时会失败。

Process.Start(@"C:\\Program Files (x86)\\Activision\\Call of Duty 4 - Modern Warfare\\iw3mp.exe","+connect 91.192.210.47:2304"); Process.Start(@“ C:\\ Program Files(x86)\\ Activision \\ Duty of Call of Duty 4-Modern Warfare \\ iw3mp.exe”,“ + connect 91.192.210.47:2304”);

The Error is Win_Improper_quit_body 错误是Win_Improper_quit_body

any ideas. 有任何想法吗。

I believe the particular executable you're trying to launch expects the working directory to be set correctly. 我相信您尝试启动的特定可执行文件期望正确设置工作目录。

var processStartInfo = new ProcessStartInfo(pathToExe, args);
processStartInfo.WorkingDirectory = Path.GetDirectoryName(pathToExe);
Process.Start(processStartInfo);

See here for more info . 有关更多信息,请参见此处

You should put the arguments part in Arguments property of ProcessStartInfo 您应该将arguments部分放在ProcessStartInfo的Arguments属性中

Here's an example: 这是一个例子:

ProcessStartInfo startInfo = new ProcessStartInfo("IExplore.exe");
            startInfo.WindowStyle = ProcessWindowStyle.Minimized;

            Process.Start(startInfo);

            startInfo.Arguments = "www.northwindtraders.com";

            Process.Start(startInfo);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM