Retrieving file installation path from registry

I am creating a WPF utility that needs to access the registry of the local computer to find out the installation path of the program.

I went to the key through Regedit and it gives the name, type and data, within the data that it shows the installation path, I would like to extract the installation path.

I know that I need to go to this registry key:

HKEY_LOCAL_MACHINE \ SOFTWARE \ Microsoft \ Windows \ CurrentVersion \ Application Paths \

then I need to access the folder inside this key with information about the installation path.

-

+5
source share
3 answers

I solved my problem, for anyone who wants a solution in the future, if you are still stuck after this, please let me know, I found it difficult to find resources.

RegistryKey key = Registry.LocalMachine.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\App Paths\myexe.exe");
string regFilePath = null;

object objRegisteredValue = key.GetValue("");

registeredFilePath = value.ToString();
+10
0

This question was very helpful to me. I came up with a helper class, wanting to play with the new Tuples.

Using an example:

public string SkypeExePath => InstalledApplicationPaths.GetInstalledApplicationPath( "lync.exe" );

Grade:

public static class InstalledApplicationPaths
{

   public static string GetInstalledApplicationPath( string shortName )
   {
      var path = GetInstalledApplicationPaths().SingleOrDefault( x => x?.ExectuableName.ToLower() == shortName.ToLower() )?.Path;
      return path;
   }

   public static IEnumerable<(string ExectuableName, string Path)?> GetInstalledApplicationPaths()
   {
      using ( RegistryKey key = Registry.LocalMachine.OpenSubKey( @"Software\Microsoft\Windows\CurrentVersion\App Paths" ) )
      {
         foreach ( var subkeyName in key.GetSubKeyNames() )
         {
            using ( RegistryKey subkey = key.OpenSubKey( subkeyName ) )
            {
               yield return (subkeyName, subkey.GetValue( "" )?.ToString());
            }
         }
      }
   }

}
0
source

All Articles