Click here to Skip to main content
12,395,871 members (65,863 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C# C#4.0
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 28-Sep-12 22:37pm
arun_pk1.4K
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

Hi,
Please Try the code below

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

Regards,
Ahmed Mandour
  Permalink  
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...
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..
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

Sorry for misunderstood
here is the code that will find the execution path of installed application

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.:

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

Regards,
Ahmed Mandour
  Permalink  

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160721.1 | Last Updated 30 Sep 2012
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100