How to detect whether a particular software is installed in windows?

喜你入骨 提交于 2019-12-07 12:00:39

问题


I am new to programming. I've been given a virtual conferencing site. Now i need to modify the site.

While the user logins into the conferencing site,it must detect whether his system has a particular software installed in his system(that software is used for making video calls.It uses ActiveX objects).

Which is the best method to detect the presence of the installed software in the system? (Frankly speaking i don't even know which language best serves the purpose)


回答1:


    public static bool IsApplictionInstalled(string p_name)
{
    string keyName;

    // search in: CurrentUser
    keyName = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall";
    if (ExistsInSubKey(Registry.CurrentUser, keyName, "DisplayName", p_name) == true)
    {
        return true;
    }

    // search in: LocalMachine_32
    keyName = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall";
    if (ExistsInSubKey(Registry.LocalMachine, keyName, "DisplayName", p_name) == true)
    {
        return true;
    }

    // search in: LocalMachine_64
    keyName = @"SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall";
    if (ExistsInSubKey(Registry.LocalMachine, keyName, "DisplayName", p_name) == true)
    {
        return true;
    }

    return false;
}

private static bool ExistsInSubKey(RegistryKey p_root, string p_subKeyName, string p_attributeName, string p_name)
{
    RegistryKey subkey;
    string displayName;

    using (RegistryKey key = p_root.OpenSubKey(p_subKeyName))
    {
        if (key != null)
        {
            foreach (string kn in key.GetSubKeyNames())
            {
                using (subkey = key.OpenSubKey(kn))
                {
                    displayName = subkey.GetValue(p_attributeName) as string;
                    if (p_name.Equals(displayName, StringComparison.OrdinalIgnoreCase) == true)
                    {
                        return true;
                    }
                }
            }
        }
    }
    return false;
}



回答2:


You can't really detect this as you have no access to the system. Your web app should simply try to create an instance of that ActiveX and display a message to the user if that fails.




回答3:


Thanks everyone. But i used this program in C#. I created this class library ,loaded the dll in the webpage and use the IsApplicationInstalled method.

public static bool IsApplicationInstalled(string p_name)
{
string displayName;
RegistryKey key;

// search in: CurrentUser
key = Registry.CurrentUser.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall");
foreach (String keyName in key.GetSubKeyNames())
{
    RegistryKey subkey = key.OpenSubKey(keyName);
    displayName = subkey.GetValue("DisplayName") as string;
    if (p_name.Equals(displayName, StringComparison.OrdinalIgnoreCase) == true)
    {
        return true;
    }
}

// search in: LocalMachine_32
key = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall");
foreach (String keyName in key.GetSubKeyNames())
{
    RegistryKey subkey = key.OpenSubKey(keyName);
    displayName = subkey.GetValue("DisplayName") as string;
    if (p_name.Equals(displayName, StringComparison.OrdinalIgnoreCase) == true)
    {
        return true;
    }
}

// search in: LocalMachine_64
key = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall");
foreach (String keyName in key.GetSubKeyNames())
{
    RegistryKey subkey = key.OpenSubKey(keyName);
    displayName = subkey.GetValue("DisplayName") as string;
    if (p_name.Equals(displayName, StringComparison.OrdinalIgnoreCase) == true)
    {
        return true;
    }
}
// NOT FOUND
return false;

}



来源:https://stackoverflow.com/questions/6995482/how-to-detect-whether-a-particular-software-is-installed-in-windows

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!