how to find the execution path of a installed software

后端 未结 6 1346
夕颜
夕颜 2020-12-05 16:26

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 install

6条回答
  •  温柔的废话
    2020-12-05 17:01

    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

提交回复
热议问题