0

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")
           {

           }
        }
    }
}
Soner Gönül
  • 97,193
  • 102
  • 206
  • 364
Jitendra singh
  • 413
  • 11
  • 27
  • Unclear what you are asking: Find a registry entry? Change a registry entry? Move a file on disk? Rename a file on Disk? Delete a File on Disk? Create new file on another disk? Copy file from one disk to another? – DrKoch Feb 04 '15 at 07:29
  • Sounds fishy! Writing some malware? – Sriram Sakthivel Feb 04 '15 at 07:38

1 Answers1

2

Could you try below code get "Install Location" of App?

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").Equals("ActiveTeach Images Book 3"))
                    {
                        return subkey.GetValue("InstallLocation");
                    }
                }
            }
        }
Ashish Sapkale
  • 540
  • 2
  • 13