How to execute an external EXE in the EXE's folder?

T

Tee

Hi,

I have created a program that will run another exe with parameters, but it
won't work. And after spend some times on it, I found that it's because the
EXE will have a runtime error if you run it not in it's own folder, I guess
it has some files the EXE needs.

Currently I am using System.Diagnostics.Process.Start to run the EXE, but it
will run from the location where my program is, can anyone help me with my
question?


Thanks a lot.
Tee
 
S

Shiva

Try setting the Process.StartInfo.WorkingDirectory to the EXE's own folder
before starting the process.

Hi,

I have created a program that will run another exe with parameters, but it
won't work. And after spend some times on it, I found that it's because the
EXE will have a runtime error if you run it not in it's own folder, I guess
it has some files the EXE needs.

Currently I am using System.Diagnostics.Process.Start to run the EXE, but it
will run from the location where my program is, can anyone help me with my
question?


Thanks a lot.
Tee
 
J

Jochen Kalmbach

Hi Tee,
Currently I am using System.Diagnostics.Process.Start to run the EXE,
but it will run from the location where my program is, can anyone help
me with my question?

You the "ProcessStartInfo" structure and set the "WorkingDirectory" to the
right dir.

See: ProcessStartInfo
http://msdn.microsoft.com/library/en-
us/cpref/html/frlrfSystemDiagnosticsProcessStartInfoClassTopic.asp

--
Greetings
Jochen

My blog about Win32 and .NET
http://blog.kalmbachnet.de/
 
J

Jon Skeet [C# MVP]

Tee said:
I have created a program that will run another exe with parameters, but it
won't work. And after spend some times on it, I found that it's because the
EXE will have a runtime error if you run it not in it's own folder, I guess
it has some files the EXE needs.

Currently I am using System.Diagnostics.Process.Start to run the EXE, but it
will run from the location where my program is, can anyone help me with my
question?

Try using ProcessStartInfo.WorkingDirectory.
 
T

Tee

What's the full namespace for Process.StartInfo?
Is it System.Diagnostics.ProcessStartInfo ?

Why I can't see the WorkingDirectory there...
 
R

Rajesh R

Hi,
Use ProcessStartInfo in System.Diagnostics to specify the working directory
that the 'another exe' needs and use the overloaded Start() (which accepts
the ProcessStartInfo) to start the other program.

+Rajesh R
 
J

Jon Skeet [C# MVP]

Tee said:
What's the full namespace for Process.StartInfo?
Is it System.Diagnostics.ProcessStartInfo ?

The full *type* name for ProcessStartInfo is
System.Diagnostics.ProcessStartInfo, yes. The namespace is just
System.Diagnostics.
Why I can't see the WorkingDirectory there...

Were you trying to access it as if it were a static property? You need
to create an instance of ProcessStartInfo, set all the appropriate
properties (FileName, Arguments etc) and then call
Process.Start(myProcessStartInfo)
 
G

Guest

how can I start this one:

rundll32.exe C:\WINDOWS\System32\shimgvw.dll,ImageView_Fullscreen
path\image.tif

the string above gives me the specified path was not found. Actually I can't
even start the windows pictures and fax viewer empty (w/o an image loaded
into it)
 

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