duminică, 16 ianuarie 2011

Finding the path to an installed application in C#

Well, you can find the path to a locally installed application by querying the windows registry.
The information is here:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\

Example photoshop.exe

I wrote this function in C# to do this for me:




///
/// get the path to a specific application from the registry
///

/// name of the application exe
///
public static string GetApplicationPath(string ExeName)
{
try
{
RegistryKey OurKey = Registry.LocalMachine;
OurKey = OurKey.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\App Paths\"+ExeName, true);
if (OurKey != null)
return OurKey.GetValue("").ToString();
else
return "";
}
catch(Exception ex)
{
return "";
}
}

Niciun comentariu:

Trimiteți un comentariu