我需要计算机上已安装应用程序的列表及其路径目录,我找到了这个:
//Registry path which has information of all the softwares installed on machine
string uninstallKey = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall";
using (RegistryKey rk = Registry.LocalMachine.OpenSubKey(uninstallKey))
{
foreach (string skName in rk.GetSubKeyNames())
{
using (RegistryKey sk = rk.OpenSubKey(skName))
{
// we have many attributes other than these which are useful.
Console.WriteLine(sk.GetValue("DisplayName") +
" " + sk.GetValue("DisplayVersion"));
}
}
}
我如何获得路径?我试过 sk.GetValue("DisplayPath")
但它不起作用。
谢谢!
最佳答案
每个软件都会有一个不同的 InstallLocation 名称,如果它存在的话。
永远是 UninstallString
,它返回卸载程序 (exe) 的路径,您可以从中删除目录。
但是,您应该知道,如果您使用 HKEY_CURRENT_USER,您不会在那里获得所有已安装的程序。
您应该通过 HKEY_LOCAL_MACHINE。
因此,您正在寻找的代码是:
string uninstallExePath = sk.GetValue("UninstallString");
DirectoryInfo directory = new FileInfo(uninstallExePath).Directory;
string directoryPath = directory.FullName;
关于c# - 在注册表中查找应用程序路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10459977/