如何从注册表中获取产品的安装位置? [英] how to fetch Install location of products from registry?

查看:111
本文介绍了如何从注册表中获取产品的安装位置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨所有 

i想要在我的应用中获取所有产品的安装位置,所以为此我使用注册表类并使用下面的字符串值为
"SOFTWARE \\ Microsoft \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ Wow6432Node\\Microsoft\\Windows\\CurrentVersion\\UnInstall"对于64位版本。

但它没有给我所有产品的详细信息,例如在注册表编辑器的上述路径中可用的
notepad ++但是使用我的代码它不是显示记事本的值。

 StreamWriter sw = new StreamWriter(@" D:\ localmachineProducts64.txt",true); 
using(RegistryKey rk = Registry.LocalMachine.OpenSubKey(uninstallKey))
{
foreach(rk.GetSubKeyNames()中的字符串skName)
{
using(RegistryKey) sk = rk.OpenSubKey(skName))
{
try
{
sw.Write(sk.GetValue(" DisplayName")+" \t" + sk .GetValue(QUOT; INSTALLLOCATION"));
sw.Write(sw.NewLine);
count ++;
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
sw.Write("总计数:=" + count);
}
sw.Close();




sumitk

解决方案

你好sumitk,


如果你只想获得程序的安装位置,下面的注册表路径是您的不错选择。除了免费安装程序,大多数程序都会找到路径。



SOFTWARE \ Microsoft \ Windows \ CurrentVersion \App Paths \


以下是一个简单的示例,当然它包括记事本++信息。

 RegistryKey localKey = RegistryKey.OpenBaseKey(RegistryHive。 LocalMachine,RegistryView.Registry64); 
localKey = localKey.OpenSubKey(@"SOFTWARE \ Microoft \ Windows \ CurrentVersion \ App Paths \",真实);
foreach(localKey.GetSubKeyNames()中的字符串skName)
{
使用(RegistryKey sk = localKey.OpenSubKey(skName))
{
try
{
Console.WriteLine(skName);
Console.WriteLine(" Default" + sk.GetValue(null));
Console.WriteLine(sk.GetValue(" Path")+" \t");

}
catch(exception ex)
{
Console.WriteLine(ex.Message);
}
}
}


祝你好运,


Neil Hu


Hi all 
i want to fetch install location of all products in my app so for that purpose i am using registry class and using below string value for it
"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\UnInstall"
and
"SOFTWARE\\Wow6432Node\\Microsoft\\Windows\\CurrentVersion\\UnInstall" for 64 bit version.
but it is not giving me details of all products for example
notepad ++ available in above path in registry editor but using my code it is not displaying the values for notepad.

  StreamWriter sw = new StreamWriter(@"D:\localmachineProducts64.txt", true);
            using (RegistryKey rk = Registry.LocalMachine.OpenSubKey(uninstallKey))
            {
                foreach (string skName in rk.GetSubKeyNames())
                {
                    using (RegistryKey sk = rk.OpenSubKey(skName))
                    {
                        try
                        {
                            sw.Write(sk.GetValue("DisplayName") + "\t" + sk.GetValue("InstallLocation"));
                            sw.Write(sw.NewLine);
                            count++;
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(ex.Message);
                        }
                    }
                }
                sw.Write("Total count  :=" + count);
            }
            sw.Close();


sumitk

解决方案

Hello sumitk,

If you just want to obtain the program's install location, the below registry path is good choice for you. Most of all program you will find the path except free-installation programs.

SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\

The following is a simple example and of course it  includes notepad++ information.

            RegistryKey localKey = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64);
            localKey = localKey.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\", true);
            foreach (string skName in localKey.GetSubKeyNames())
            {
                using (RegistryKey sk = localKey.OpenSubKey(skName))
                {
                    try
                    {
                        Console.WriteLine(skName);
                        Console.WriteLine("Default" + sk.GetValue(null));
                        Console.WriteLine(sk.GetValue("Path") + "\t");
      
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                    }
                }
            }

Best regards,

Neil Hu


这篇关于如何从注册表中获取产品的安装位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆