Process.start()方法无法启动用WPF编写的.exe文件 [英] Process.start() method cannot start a .exe file written with WPF

查看:576
本文介绍了Process.start()方法无法启动用WPF编写的.exe文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我今天尝试使用Process.start()方法启动一个进程(一个用WPF编写的称为Chess.exe的桌面3D游戏)方法,但是我在任务管理器中找不到它,并且没有窗口显示.当我尝试使用Win32 API函数CreatProcess启动它时,也会显示相同的内容.我尝试了其他用WPF编写的.exe文件,它们运行良好.目录也正确.我已经搜索了许多网页,但没有答案.
这是代码:

I''m trying to start a process(a desktop 3D game called chess.exe written with WPF) with Process.start()method today,but I can noly find it in the task manager and no window shows up.The same thing shows when I try to start it with Win32 API function CreatProcess.I have tried other .exe files written with WPF ,they works well. The directory is right,too.I have searched many web pages,but there is no answer.
Here is the code:

ProcessStartInfo startInfo = new ProcessStartInfo("E:\\Visual Studio 2010\\Projects\\chess\\chess\\bin\\Debug\\chess.exe");
startInfo.WindowStyle = ProcessWindowStyle.Normal;
startInfo.CreateNoWindow = false;
startInfo.UseShellExecute = true;
Process.Start(startInfo);

推荐答案

与WPF无关.

我知道这个问题.您需要将字符串夹在引号中:

It has nothing to do with WPF.

I know this problem. You need to sandwich your string in quotation marks:

//verbose string literal syntax:
string application = @"""E:\Visual Studio 2010\Projects\chess\chess\bin\Debug\chess.exe""";

//regular escape string literal syntax:
string app2 = "\"E:\\Visual Studio 2010\\Projects\\chess\\chess\\bin\\Debug\\chess.exe\"";

//...

ProcessStartInfo startInfo = new ProcessStartInfo(application);
//...



我必须解释为什么吗?提示:您的路径中有一个空格字符.如果仍然没有收到,请问一个后续问题.

对您的警告:如果您在代码中使用硬编码的立即数,则无法创建可支持的应用程序.至于路径名,原则上它不能以可移植的方式工作.所有路径字符串都应始终基于入口程序集的主要可执行模块计算或放入配置文件中.或者,用户可以使用文件对话框指定它.永远不会有一个硬编码的值可以工作.

—SA



Do I have to explain why? A hint: there is a blank space character in your path. If you still did not get it, please ask a follow-up question.

A big warning for you: you cannot make supportable application if you use immediate constants hard-coded in your code. As to path names, it cannot work in portable way in principle. All path strings should always be calculated based on your main executable module of your entry assembly or put in configuration file. Alternatively, the user can specify it using a file dialog. There is no case when a hard-coded value could work, ever.

—SA


尝试

Try

Process.Start("\"E:\\Visual Studio 2010\\Projects\\chess\\chess\\bin\\Debug\\chess.exe\"");


这篇关于Process.start()方法无法启动用WPF编写的.exe文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆