views:

385

answers:

2

Hi all,

I have a program that crashes when I execute it with System.Diagnostics.Process.Start in C#, but works fine if I execute a shortcut or batch file that runs the exe. Are there any alternative means of executing programs in C#, or any reasons why Process.Start might not work compared to the shortcut or batch file? I'd rather not have to generate a batch or shortcut file to run the application.

Thanks

+1  A: 

I think it's important to understand why your application is crashing in this situation instead of prematurely working around the problem. There is very little special about Process.Start and using any means of starting the process will essentially compile down to the same code under the hood.

Can you give us any information on why it's crashing? Have you tried attaching a debugger on crash to see what's going on?

JaredPar
+3  A: 

I would definitely look at making sure you are setting your "working directory" correctly. Just because you launch an EXE doesn't mean its working directory will be the folder it resides in. It will probably be the folder where the main app is running, or if you are running from a service it could be WindowsFolder\system32.

Make sure you specify a working directory via the ProcessStartInfo.WorkingDirectory property. If you don't, DLLs that you need to load or files that you need to read may not be where you expect them to be if they are expected to be relative to the working directory.

mjmarsh