Finding .exe files at runtime?

J

John H.

Okay, I’m clearly missing something very fundamental.

I am writing c# .net 4 console app. The app processes a text file
that contains a reference to another .exe files that is to be launched
by calling System.Diagnostic.Process.Start(). I first verify that
the .exe file exists before trying to launch it. If not, I display an
appropriate runtime message.

I look for the .exe in this order.
(1) First, I call File.Exists([exact string specified in the file])
(2) If that fails, I look for the .exe in the current directory.
(3) If that fails, I look for the .exe in the Environment PATH.
(4) If that fails, I display an error message.

Here is the mystery:

Office 2007 is installed in this system. When my program is running,
the file “Excel.exe” does not exist in the current directory, nor does
it exist in any directory in the Environmental PATH. But, if I call
System.Diagnostic.Process.Start(“Excel.exe”), Excel launches just
fine.

How is the system finding the Excel.exe file?

My validation that first verifies the .exe exists fails because it
cannot find Excel.exe. I can hard code and exception for Microsoft
Office apps, but that seems a little sloppy to me. I’d rather figure
out what is going on. I’ve looked through the registry. There are
bunch of references to Excel.exe and the Office directory in the c:
\Program Files. But, nothing really jumped out at me.

Thanks,
John
 
J

John H.

Pete,

Okay, executing through the shell was the concpetual piece that I
was missing. I don't work with this kind of code that often. I like
your idea of just trying to start the process with the string
reference to the .exe as it is entered in the test file, and then only
handling an excpetion if that fails. The resulting code is much
simpler and faster.

Thanks,
JohnH
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top