Getting the path of an exe

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi
Using C#, how we can get the absolute path of an exe
For example, if I have x.exe, which I want to start in some other process, How I can get the absolute path of this exe
Now I am hard coding the exe's name, I want to avoid that

snippet
string myexepath="......./x.exe"
Process p=Process.Start(myexepath)
I want to get the x.exe path through the program itself
Can anybody suggest some method for doing this
Thanks and Regards
Saty
 
Application.StartupPath

Satya said:
Hi,
Using C#, how we can get the absolute path of an exe.
For example, if I have x.exe, which I want to start in some other process,
How I can get the absolute path of this exe.
 
Hi Satya,

But how would you know which exe you want to start?

--
Miha Markic [MVP C#] - RightHand .NET consulting & software development
miha at rthand com
www.rthand.com

Satya said:
Hi,
Using C#, how we can get the absolute path of an exe.
For example, if I have x.exe, which I want to start in some other process,
How I can get the absolute path of this exe.
 
You can try this:

string myDir =
Process.GetCurrentProcess().MainModule.FileName.Substring(0,pc.MainModule.Fi
leName.LastIndexOf(@"\")));


José

Satya said:
Hi,
Using C#, how we can get the absolute path of an exe.
For example, if I have x.exe, which I want to start in some other process,
How I can get the absolute path of this exe.
 
I know the exe's name. The problem is it may be installed any of the possible hard disks and I can't hard code that.
In client's machine if it is in any other path than what I hard coded, problem. That's why I need the absolute path.
Satya
 
Hi Satya,

You might search the available disks at the start and store the path
somewhere.
Or you can prompt user to enter the path (Open File dialog perhaps).

--
Miha Markic [MVP C#] - RightHand .NET consulting & software development
miha at rthand com
www.rthand.com


Satya said:
I know the exe's name. The problem is it may be installed any of the
possible hard disks and I can't hard code that.
In client's machine if it is in any other path than what I hard coded,
problem. That's why I need the absolute path.
 
Back
Top