Click here to Skip to main content
15,890,438 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello i am trying to get path of an installed application
How can i achieve this


Currently i am trying to use
String path = Environment.GetEnvironmentVariable("path");


but this doesnot give the application path .. here i am trying to get the vpnClient.exe
Posted

Hi,
Please Try the code below

C#
String path = System.Windows.Forms.Application.StartupPath;


Regards,
Ahmed Mandour
 
Share this answer
 
v2
Comments
arun_pk 29-Sep-12 5:36am    
Application ?? please say the namespace
Ahmed Mandur 29-Sep-12 5:40am    
I have edited the solution with your last requirements
Regards,
arun_pk 29-Sep-12 12:10pm    
Sorry this is not at all what i was asking for...
[no name] 29-Sep-12 14:35pm    
For better answers you need to complete your question.
arun_pk 29-Sep-12 12:11pm    
but this doesnot give the application path .. here i am trying to get the vpnClient.exe

this is what i was looking for
the answer you given was no where related to this..
sorry to say this..
Sorry for misunderstood
here is the code that will find the execution path of installed application

C#
private const string keyBase = @"SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths";

        private string GetPathForExe(string fileName)
        {
            RegistryKey localMachine = Registry.LocalMachine;
            RegistryKey fileKey = localMachine.OpenSubKey(string.Format(@"{0}\{1}", keyBase, fileName));
            object result = null;
            if (fileKey != null)
            {
                result = fileKey.GetValue(string.Empty);
            }
            fileKey.Close();

            return (string)result;
        } 


To use this code Eg.:

C#
string Path = GetPathForExe("firefox.exe");


Regards,
Ahmed Mandour
 
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