Path of an exe

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

Guest

Hi
I think I was not clear in putting my question
The scenario is like this
I have to start an exe from my application, which runs as a process
I know the name of the exe, but don't know the path. It can exist anywhere in the machine
I want to get the absolute path of the exe, using my application
How I can get that?? At present I am using the absolute path of the exe hardcoded. But I can't do this, when the application runs in some other's pc as the exe may be in some other folder
Can U give some suggestion, how I can get the absolute path?
Saty
 
Satya.

You would have to implement a recursive fileseach method which
traverses the file system, looking for a file with the desired name. Have
a look in the System.IO namespace for FileInfo and DirectoryInfo
classes.

Basically what you need to do is create an initial DirectoryInfo class
which points at, for example, C:\ .. Then you call GetFiles() on it and
loop them, looking for the file. If it was not found then you call the
GetDirectories() method and pass each of them (until you find match)
to your recursive method, repeating the step.

I'm just about to head out the door and I do not have the time to write
some code for you.. sorry.

Hope this helps,

//Andreas

Satya said:
Hi,
I think I was not clear in putting my question.
The scenario is like this.
I have to start an exe from my application, which runs as a process.
I know the name of the exe, but don't know the path. It can exist anywhere in the machine.
I want to get the absolute path of the exe, using my application.
How I can get that?? At present I am using the absolute path of the exe
hardcoded. But I can't do this, when the application runs in some other's pc
as the exe may be in some other folder.
 
use SearchPath WinAPI by P/Invoke

--------------------------------------------
Manish Agarwal <[email protected]>

Satya said:
Hi,
I think I was not clear in putting my question.
The scenario is like this.
I have to start an exe from my application, which runs as a process.
I know the name of the exe, but don't know the path. It can exist anywhere in the machine.
I want to get the absolute path of the exe, using my application.
How I can get that?? At present I am using the absolute path of the exe
hardcoded. But I can't do this, when the application runs in some other's pc
as the exe may be in some other folder.
 
Perhaps you should be a little more specific. What file are you looking for? Is this some file
which users at your company may have dropped anywhere on their machine? If so, perhaps your company
should employ some sort of standard method to distribute applications. Maybe you can distribute the
target executable along with your program.

Are you trying to start Internet Explorer, or the user's default web browser? If so, you can get
that from the HKEY_CLASSES_ROOT\http\shell registry key. If you need to know how, let me know.

Are you trying to start some program that the user may have installed just about anywhere, but which
would have a shortcut on their desktop or in their Start menu? If you can find the shortcut (which
should be much quicker and less disk-intensive than traversing the entire harddrive), you can
execute the shortcut instead, or even determine the path to the actual executable from the shortcut.

Satya said:
Hi,
I think I was not clear in putting my question.
The scenario is like this.
I have to start an exe from my application, which runs as a process.
I know the name of the exe, but don't know the path. It can exist anywhere in the machine.
I want to get the absolute path of the exe, using my application.
How I can get that?? At present I am using the absolute path of the exe hardcoded. But I can't do
this, when the application runs in some other's pc as the exe may be in some other folder.
 
Satya,

Please refer to your previous post on the topic for a
working example on how to locate a given file by using
the SearchPath API.


Hope this helps,

//Andreas
 
Back
Top