Reputation: 11
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
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