正如这里建议的那样,我需要遍历条目
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\
找出我的应用程序的安装路径.如何迭代,以便我可以找到给定DisplayName的 InstallLocation值.如何在C#中高效地完成它.
以下是实现目标的代码:
class Program { static void Main(string[] args) { RegistryKey key = Registry.LocalMachine.OpenSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall"); foreach (var v in key.GetSubKeyNames()) { Console.WriteLine(v); RegistryKey productKey = key.OpenSubKey(v); if (productKey != null) { foreach (var value in productKey.GetValueNames()) { Console.WriteLine("\tValue:" + value); // Check for the publisher to ensure it's our product string keyValue = Convert.ToString(productKey.GetValue("Publisher")); if (!keyValue.Equals("MyPublisherCompanyName", StringComparison.OrdinalIgnoreCase)) continue; string productName = Convert.ToString(productKey.GetValue("DisplayName")); if (!productName.Equals("MyProductName", StringComparison.OrdinalIgnoreCase)) return; string uninstallPath = Convert.ToString(productKey.GetValue("InstallSource")); // Do something with this valuable information } } } Console.ReadLine(); } }
编辑:有关查找"应用程序安装路径"的更全面方法,请参阅此方法,它将using
按照注释中的建议演示处理.
/sf/ask/17360801/