Jitendra Kumar Singh
Jitendra Kumar Singh

Reputation: 11

how to get installed software path from registry that is installed in local system

I need to replace the file which is installed in any drive like C,D,E... I want to find the installed file path from registry and replace this file to other file. software will be installed in any drive. I want to replace file.

I am using this code.

how to find the installed file path and replace to other file in C# using registry.

        string registry_key = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall";
        using (Microsoft.Win32.RegistryKey key = Registry.LocalMachine.OpenSubKey(registry_key))
        {
            foreach (string subkey_name in key.GetSubKeyNames())
            {
                using (RegistryKey subkey = key.OpenSubKey(subkey_name))
                {
                    // Console.WriteLine(subkey.GetValue("DisplayName"));

                    if (subkey.GetValue("DisplayName") == "ActiveTeach Images Book 3")
                    {

                    }
                }
            }
        }

Upvotes: 0

Views: 1048

Answers (1)

Jitendra Kumar Singh
Jitendra Kumar Singh

Reputation: 11

        string Software = null;
        string SoftwareKey = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall";
        using (RegistryKey rk = Registry.LocalMachine.OpenSubKey(SoftwareKey))
        {
            foreach (string skName in rk.GetSubKeyNames())
            {
                using (RegistryKey sk = rk.OpenSubKey(skName))
                {
                    try
                    {
                        if (!(sk.GetValue("DisplayName") == null))
                        {
                            if (sk.GetValue("InstallLocation") == null)
                            {
                                // Software += sk.GetValue("DisplayName") + " - Install path not known\n";
                            }
                            else
                            {
                                string ext_file = Convert.ToString(sk.GetValue("DisplayName"));
                                string cmp_file = "ActiveTeach Images Book 3";
                                if (ext_file == cmp_file)
                                {
                                    Software = sk.GetValue("DisplayName") + " - " + sk.GetValue("InstallLocation") + "\n";
                                    // lblMsg.Content = Software;
                                }
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                    }
                }
            }
        }

Upvotes: 1

Related Questions