Click here to Skip to main content
15,885,537 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
Hellow every body,
find path programetically given .exe file
if reply greatly appriciate.
Thank U.
Posted
Comments
Prerak Patel 9-Nov-11 1:00am    
Not clear. Do you want to search the exe by name?
Sergey Alexandrovich Kryukov 9-Nov-11 1:08am    
I don't think so. I have a guess, answered according to it -- pleas see...
--SA
Bojjaiah 9-Nov-11 3:38am    
yes
P.Salini 9-Nov-11 1:01am    
Clarify your question
Bojjaiah 9-Nov-11 2:39am    
actually we develop a webapplication on that printmethod is there.
the print method is requiere for acrobrd32.exe.
so, i want to validate the client system have acrobrd32.exe is there or not before call a print method
it's ok for u
Thank u.

The question is poorly formulated, so no one can be 100% sure what path do you mean.

For a currently running application, you can find a path to the main module of its entry assembly, which is usually some *.EXE file:

C#
string exeFile =
   System.Reflection.Assembly.GetEntryAssembly().Location;


Note: there are several other methods, but some of them are not reliable (not universal enough) as the result depends on how the application is hosted; for example, it might give different result when hosted as a Windows Service application by a Service Controller or even by Visual Studio debug host.

—SA
 
Share this answer
 
v2
Hi guys finally i have solved this answer with help of my tl.
//solution
//method like this
static IEnumerable<string> Search(string root, string searchPattern)
{
Queue<string> dirs = new Queue<string>();
dirs.Enqueue(root);
while (dirs.Count > 0)
{
string dir = dirs.Dequeue();
// files
string[] paths = null;
try
{
paths = Directory.GetFiles(dir, searchPattern);
}
catch
{
}
// swallow
if (paths != null && paths.Length > 0)
{
foreach (string file in paths)
{
yield return file;
}
}
// sub-directories
paths = null;
try
{
paths = Directory.GetDirectories(dir);
}
catch
{
}
// swallow
if (paths != null && paths.Length > 0)
{
foreach (string subDir in paths)
{
dirs.Enqueue(subDir);
}
}
}
}


//call tat method like this
foreach (string match in Search"C:\\","AcroRd32.exe"))
{
Response.Write(match);
return;
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900