Retrieving file installation path from registry

后端 未结 3 1712
谎友^
谎友^ 2021-01-18 14:44

I am creating a WPF utility which needs to access the registry of the local machine, to then find out the installation path of the program.

I\'ve navigated to the ke

相关标签:
3条回答
  • 2021-01-18 15:04

    I solved my problem, to anyone who wants a solution in the future if your still stuck after this please message me, I found it was hard to find the resources.

    RegistryKey key = Registry.LocalMachine.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\App Paths\myexe.exe");
    string regFilePath = null;
    
    object objRegisteredValue = key.GetValue("");
    
    registeredFilePath = value.ToString();
    
    0 讨论(0)
  • 2021-01-18 15:11

    To read registry keys you should use Microsot.Windows.RegistryKey class, class Registry can open for you the RegistryKey.

    0 讨论(0)
  • 2021-01-18 15:21

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

    Example usage:

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

    The class:

    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 讨论(0)
提交回复
热议问题