我如何检查是否安装了应用程序 [英] How I Can Check If App Installed

查看:97
本文介绍了我如何检查是否安装了应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

hi


i有这个代码来检查.net是否已安装,并且它工作得非常好



  string 键; 
bool data = false ;

尝试
{
key = Registry.LocalMachine.OpenSubKey( SOFTWARE)。OpenSubKey( Microsoft)。OpenSubKey( Windows)。OpenSubKey( CurrentVersion)。OpenSubKey( 卸载)。GetValue( 50727)。ToString( );
}
catch (例外)
{
}
data =(key == 50727-50727);
label1.text = 已安装;







i试图使用相同的代码更改anothor应用程序的位置,但它会结束



32bit系统



  string  key1; 
bool data1 = false ;


尝试
{
key1 = Registry.LocalMachine.OpenSubKey( SOFTWARE)。OpenSubKey( Wow6432Node)。OpenSubKey( Microsoft)。OpenSubKey(< span class =code-string> Windows)。OpenSubKey( < span class =code-string> CurrentVersion)。OpenSubKey( 卸载 ).OpenSubKey( Mozilla Firefox 38.0.1(x86 zh-CN))。GetValue(< span class =code-string> DisplayName)。ToString();
}
catch (例外)
{
}

data1 =(key1 = = Mozilla Firefox 38.0.1(x86 zh-CN));

label10.Text = Mozilla Firefox - + data1.ToString( );







64bit系统



  string  key1; 
bool data1 = false ;


尝试
{
key1 = Registry.LocalMachine.OpenSubKey( SOFTWARE)。OpenSubKey( Microsoft)。OpenSubKey( Windows)。OpenSubKey(< span class =code-string> CurrentVersion)。OpenSubKey( < span class =code-string>卸载)。OpenSubKey( Mozilla Firefox 38.0.1( x86 zh-CN))。GetValue( DisplayName)。ToString() ;
}
catch (例外)
{
}

data1 =(key1 = = Mozilla Firefox 38.0.1(x86 zh-CN));

label10.Text = Mozilla Firefox - + data1.ToString( );





任何想法?

解决方案

阅读: http://stackoverflow.com/questions/908850/get-installed-applications-in- a-system [ ^ ]


感谢所有人,这解决了我的问题

检查应用程序是否安装在注册表中





< pre lang =c#> public static 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子键 in key.GetSubKeyNames()。选择(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子键 in key.GetSubKeyNames()。选择(keyName = > key.OpenSubKey(keyName)))
{
displayName = subkey.GetValue( DisplayName as string ;
if (displayName!= null && displayName.Contains(c_name))
{
return true ;
}
}
key.Close();
}
返回 false ;
}











我只是简单地使用



 如果(checkInstalled ( 应用程序名称))


hi
i have this code to check if .net installed , and it work very good

string key;
bool data = false;

 try
            {
                key = Registry.LocalMachine.OpenSubKey("SOFTWARE").OpenSubKey("Microsoft").OpenSubKey("Windows").OpenSubKey("CurrentVersion").OpenSubKey("Uninstall").GetValue("50727").ToString();
            }
            catch (Exception)
            {
            }
data = (key == "50727-50727");
label1.text = "installed";




i tried to used same code with change the location for anothor apps but it faild

32bit system

string key1;
bool data1 = false;


try
          {
              key1 = Registry.LocalMachine.OpenSubKey("SOFTWARE").OpenSubKey("Wow6432Node").OpenSubKey("Microsoft").OpenSubKey("Windows").OpenSubKey("CurrentVersion").OpenSubKey("Uninstall").OpenSubKey("Mozilla Firefox 38.0.1 (x86 en-GB)").GetValue("DisplayName").ToString();
          }
          catch (Exception)
          {
          }

          data1 = (key1 == "Mozilla Firefox 38.0.1 (x86 en-GB)");

          label10.Text = "Mozilla Firefox - " + data1.ToString();




64bit system

string key1;
 bool data1 = false;


 try
           {
               key1 = Registry.LocalMachine.OpenSubKey("SOFTWARE").OpenSubKey("Microsoft").OpenSubKey("Windows").OpenSubKey("CurrentVersion").OpenSubKey("Uninstall").OpenSubKey("Mozilla Firefox 38.0.1 (x86 en-GB)").GetValue("DisplayName").ToString();
           }
           catch (Exception)
           {
           }

           data1 = (key1 == "Mozilla Firefox 38.0.1 (x86 en-GB)");

           label10.Text = "Mozilla Firefox - " + data1.ToString();



any idea ?

解决方案

Read this : http://stackoverflow.com/questions/908850/get-installed-applications-in-a-system[^]


thanks for all , this solved my Q
Check if application is installed in registry


public static 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;
}






And I simply just call it using

if(checkInstalled("Application Name"))


这篇关于我如何检查是否安装了应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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