新手如何使用 C# 检查已安装的浏览器

发布于 2024-12-06 20:17:50 字数 1714 浏览 0 评论 0原文

我正在构建一个应用程序,它是一个简单的应用程序,我想要它做的就是以简单的英语和架构显示操作系统信息,并检查已安装的浏览器,然后我将添加它删除 cookie 等功能。

我所坚持的是浏览器检测部分。谁能指点我一些不错的教程或方法?谢谢。

编辑: 好的,我终于使用下面 hcb 提供的代码片段和其他人的评论(谢谢大家)写出了一些工作代码。到目前为止,它正在做我想要的事情,所以我想我可以为那些尝试做同样事情的人分享我所拥有的东西:

RegistryKey browserKeys;

        browserKeys = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\WOW6432Node\Clients\StartMenuInternet");

        if (browserKeys == null)
        {
            browserKeys = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Clients\StartMenuInternet");
        }

        string[] browserNames = browserKeys.GetSubKeyNames();

        foreach (string browser in browserNames)
        {
            using (RegistryKey tempKey = browserKeys.OpenSubKey(browser))
            {
                foreach (string keyName in tempKey.GetValueNames())
                {
                    if (tempKey.GetValue(keyName).ToString() == "Internet Explorer")
                    {
                        internetExplorerButton.Enabled = true;
                        internetExplorerButton.BackgroundImage = Properties.Resources.iExplorer;

                        if (internetExplorerButton.Enabled == true)
                        {
                            Label ieLabel = new Label();
                            ieLabel.Text = "Found!";
                            explorerLable.Text = ieLabel.Text;
                        }
                    }

令我极度烦恼的是,我注意到谷歌想要在本地应用程序数据中安装他们的浏览器。我成功地解决了这个问题,再次单独编写代码并检查:

Registry.CurrentUser.OpenSubKey(@"SOFTWARE\Google\Update\Clients");

Edit2:检查Chrome的CurrentUser似乎对一些朋友来说效果很好,所以一定没问题。

I am building an app and its a simple one, all I want it to do is display os information in plain english and the architecture as well as check for installed browsers and then I'll add the ability for it to delete cookies and what not.

What Im stuck on is the browser detection part. Can anyone point me to some decent tutorials or how tos? Thanks.

Edit: OK I managed to finally scratch out some working code using the snippet provided by hcb below and the comments from the others (thanks everyone). So far it is doing exactly what I want so I thought id share what I have for those trying to do the same thing:

RegistryKey browserKeys;

        browserKeys = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\WOW6432Node\Clients\StartMenuInternet");

        if (browserKeys == null)
        {
            browserKeys = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Clients\StartMenuInternet");
        }

        string[] browserNames = browserKeys.GetSubKeyNames();

        foreach (string browser in browserNames)
        {
            using (RegistryKey tempKey = browserKeys.OpenSubKey(browser))
            {
                foreach (string keyName in tempKey.GetValueNames())
                {
                    if (tempKey.GetValue(keyName).ToString() == "Internet Explorer")
                    {
                        internetExplorerButton.Enabled = true;
                        internetExplorerButton.BackgroundImage = Properties.Resources.iExplorer;

                        if (internetExplorerButton.Enabled == true)
                        {
                            Label ieLabel = new Label();
                            ieLabel.Text = "Found!";
                            explorerLable.Text = ieLabel.Text;
                        }
                    }

To my extreme annoyance, I noticed that Google want to install their browser in the Local App Data. I managed to work this out writing the code again separately and checking:

Registry.CurrentUser.OpenSubKey(@"SOFTWARE\Google\Update\Clients");

Edit2: Checking CurrentUser for Chrome seems to work fine for a few friends so it must be OK.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

迷你仙 2024-12-13 20:17:50

像这样:

RegistryKey browserKeys;
//on 64bit the browsers are in a different location
browserKeys =   Registry.LocalMachine.OpenSubKey(@"SOFTWARE\WOW6432Node\Clients\StartMenuInternet");
if (browserKeys == null)
    browserKeys = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Clients\StartMenuInternet");

string[] browserNames = browserKeys.GetSubKeyNames();

Like this:

RegistryKey browserKeys;
//on 64bit the browsers are in a different location
browserKeys =   Registry.LocalMachine.OpenSubKey(@"SOFTWARE\WOW6432Node\Clients\StartMenuInternet");
if (browserKeys == null)
    browserKeys = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Clients\StartMenuInternet");

string[] browserNames = browserKeys.GetSubKeyNames();
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文