c#检查注册表是否已安装程序(如果是)获取安装位置? [英] c# Check registry if program is installed if yes get install location ?

查看:104
本文介绍了c#检查注册表是否已安装程序(如果是)获取安装位置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我创建的程序都是我想查找的程序的显示名称是否存在以获取安装位置

Hello all i have created a program what i want to do is if the display name of the program im looking for exists to grab the installedlocation 

如此处所示

as shown here 

我想出了这段代码来检查是否已安装该程序,但是我不确定如果找到该程序我将如何处理,请获取安装位置.

i have come up with this code to get check the if the program is installed but im not sure how i would go about if the program is found get the installlocation. 

我拥有的代码

        public bool checkInstalled(string c_name)
        {
            string displayName;

            string registryKey = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall";
            RegistryKey key = Registry.LocalMachine.OpenSubKey(registryKey);
            if (key != null)
            {
                foreach (RegistryKey subkey in key.GetSubKeyNames().Select(keyName => key.OpenSubKey(keyName)))
                {
                    displayName = subkey.GetValue("DisplayName") as string;
                    if (displayName != null && displayName.Contains(c_name))
                    {
                        return true;
                    }
                }
                key.Close();
            }

            registryKey = @"SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall";
            key = Registry.LocalMachine.OpenSubKey(registryKey);
            if (key != null)
            {
                foreach (RegistryKey subkey in key.GetSubKeyNames().Select(keyName => key.OpenSubKey(keyName)))
                {
                    displayName = subkey.GetValue("DisplayName") as string;
                    if (displayName != null && displayName.Contains(c_name))
                    {
                        return true;
                    }
                }
                key.Close();
            }
            return false;
        }

这就是我的称呼.

        private void simpleButton4_Click(object sender, EventArgs e)
        {
            if (elfpcdj.checkInstalled("PCDJ BLUE VRM"))
            {
                MessageBox.Show("it exists");
                // this is what i have tryied but failed. 
                string InstallPath = (string)Registry.GetValue(@"PCDJ BLUE VRM", "InstallLocation", null);
                if (InstallPath != null)
                {
                    MessageBox.Show(InstallPath);
                }
            }
            else
            {
                MessageBox.Show("it dont exist");
            }
        }

所以我要做的是找到该程序,它表明它在发现程序时就存在,我希望它查找安装位置并将其打印到消息框中或保存为字符串. ;

so what i want it to do is find the program witch it does it shows it exists when the program is found i want it to look for the install location and print it out to a message box or save it to string. 

推荐答案

嗨elfenliedtopfan2,

Hi elfenliedtopfan2,

谢谢您在这里发布.

对于您的问题,您想查找安装位置并通过消息框显示它.  

我测试了您的代码.对于注册表. GetValue方法,参数keyName必须是完整的注册表 地址并以有效的注册表根(HKEY_LOCAL_MACHINE)开头.

I test your code. For Registry.GetValue method, the parameter keyName must be a full registry address and start with valid registry root(HKEY_LOCAL_MACHINE). 

这是TnstallDate的IstallPath的值.

Here is the value of IstallPath of TnstallDate.

对我来说效果很好,请尝试一下.

It works well for me, please have a try.

最好的问候,

温迪


这篇关于c#检查注册表是否已安装程序(如果是)获取安装位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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