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

  • Thread starter Thread starter Tee
  • Start date Start date
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
 
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
 
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/
 
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.
 
What's the full namespace for Process.StartInfo?
Is it System.Diagnostics.ProcessStartInfo ?

Why I can't see the WorkingDirectory there...
 
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
 
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)
 
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)
 
Back
Top