How can i find the execution path of a installed software in c# for eg media player ,vlc player . i just need to find their execution path . if i have a vlc player installed in my D drive . how do i find the path of the VLC.exe from my c# coding
-
1Do you mean you want to look through the registry? – annakata May 26 '09 at 10:08
6 Answers
Using C# code you can find the path for some excutables this way:
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;
}
Use it like so:
string pathToExe = GetPathForExe("wmplayer.exe");
However, it may very well be that the application that you want does not have an App Paths key.

- 6,419
- 11
- 54
- 89

- 155,851
- 29
- 291
- 343
This method works for any executable located in a folder which is defined in the windows PATH variable:
private string LocateEXE(String filename)
{
String path = Environment.GetEnvironmentVariable("path");
String[] folders = path.Split(';');
foreach (String folder in folders)
{
if (File.Exists(folder + filename))
{
return folder + filename;
}
else if (File.Exists(folder + "\\" + filename))
{
return folder + "\\" + filename;
}
}
return String.Empty;
}
Then use it as follows:
string pathToExe = LocateEXE("example.exe");
Like Fredrik's method it only finds paths for some executables

- 28,022
- 11
- 77
- 119
-
small corrections so that your code will work: 1)All part of ur code doesnt return a value, 2)'LocateEXE'(misspelled) 3)folder + "\\" + filename. But this will work only when the Path Variables are Set by the application that u install. In most cases it wont work. And what is the else if part doing.? Can u explain that.? – SyncMaster May 27 '09 at 05:02
-
1 & 2) oops, corrected that now, 3) missed out a + "\\" + which is designed to check for folders in the path not terminated with a backslash – RobV May 28 '09 at 09:31
-
yes its true that it won't work for a lot of cases, but that's the same as Fredrik's suggestion and we both pointed out that it won't work all the time. It may be easier just to have an AppSetting or similar in your app which you ask the end user to configure to point to VLC – RobV May 28 '09 at 09:34
-
4You can simplify the inside of the `foreach` by using `Path.Combine(string, string)` instead of doing the two separate tests. – cdmckay Sep 21 '11 at 04:55
I used the CurrentVersion\Installer\Folders registry key. Just pass in the product name.
private string GetAppPath(string productName)
{
const string foldersPath = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\Folders";
var baseKey = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64);
var subKey = baseKey.OpenSubKey(foldersPath);
if (subKey == null)
{
baseKey = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32);
subKey = baseKey.OpenSubKey(foldersPath);
}
return subKey != null ? subKey.GetValueNames().FirstOrDefault(kv => kv.Contains(productName)) : "ERROR";
}

- 41
- 1
- 4
-
The problem with this answer; Even if the program is uninstalled, it still returns the same path. – Ozgur Saklanmaz Mar 22 '22 at 11:15
None of the answers worked for me. After hours of searching online, I was able to successfully get the installation path. Here is the final code.
public static string checkInstalled(string findByName)
{
string displayName;
string InstallPath;
string registryKey = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall";
//64 bits computer
RegistryKey key64 = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64);
RegistryKey key = key64.OpenSubKey(registryKey);
if (key != null)
{
foreach (RegistryKey subkey in key.GetSubKeyNames().Select(keyName => key.OpenSubKey(keyName)))
{
displayName = subkey.GetValue("DisplayName") as string;
if (displayName != null && displayName.Contains(findByName))
{
InstallPath = subkey.GetValue("InstallLocation").ToString();
return InstallPath; //or displayName
}
}
key.Close();
}
return null;
}
you can call this method like this
string JavaPath = Software.checkInstalled("Java(TM) SE Development Kit");
and boom. Cheers

- 3,863
- 1
- 27
- 17
This stackoverflow.com article describes how to get the application associated with a particular file extension.
Perhaps you could use this technique to get the application associated with certain extensions, such as avi or wmv - either Medial Player or in your case VLC player?

- 1
- 1

- 2,437
- 1
- 15
- 12