Click here to Skip to main content
15,888,111 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
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);
Posted

It has nothing to do with WPF.

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

C#
//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);
//...


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
 
Share this answer
 
v6
Comments
#realJSOP 18-May-11 13:34pm    
Changed "black" to "SPACE".
Sergey Alexandrovich Kryukov 18-May-11 14:49pm    
Thank you very much, John. You can read between characters, not only between lines :-)
--SA
xiangshimoni 18-May-11 23:37pm    
Thank you for your answer.But I still can not get it,the window does not display on the screen.
Is there any other slutions ?
Sergey Alexandrovich Kryukov 19-May-13 13:39pm    
What do you mean "other"?!! You have a bug, so fix it first. Solve the problem to make things working, don't try to work around.
And then accept this answer formally (green button), it really provides you the solution.
Don't mix up unrelated problem, solve one by one.
—SA
Member 8973214 19-May-13 11:10am    
Hi SA,
I tried all the solutions on this page, all are working fine when I open an Image
as (eg: "D:\\Vcop2\\a.bmp")
but when I try the same methods to open a game (eg: @"""D:\Vcop2\VCop2.exe""") It do not run,(no any exception) , I also tried Arguments and verb property to run as administrator but did not work. any suggestion plz. (is there any clash between GDI and DirectX?)
Try

Process.Start("\"E:\\Visual Studio 2010\\Projects\\chess\\chess\\bin\\Debug\\chess.exe\"");
 
Share this answer
 
v3
Comments
xiangshimoni 18-May-11 23:41pm    
Thanks.But it does not work,too.Maybe I should the some other methods.
Mark Salsbery 18-May-11 23:49pm    
hmm...no exception either? What's the return value? That simplified one above works for me (even without the extra quotes) on a WPF app as expected. And if you browse to that exe in Windows Explorer and double-click it then it comes up?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900