10

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.

BrandNewDev
  • 755
  • 2
  • 9
  • 16
  • 2
    possible duplicate of [How to find all the browsers installed on a machine](http://stackoverflow.com/questions/2370732/how-to-find-all-the-browsers-installed-on-a-machine) – George Duckett Sep 27 '11 at 09:54
  • The answer to the duplicate question is a link to here: http://rhizohm.net/irhetoric/post/2009/04/03/0a-Finding-All-Installed-Browsers-in-Windows-XP-and-Vista-ndash3b-beware-64bit!0a-.aspx I don't think you'll get simpler than this. – George Duckett Sep 27 '11 at 09:54
  • I have read that but I dont understand what purpose his 'Browser' class serves. What would his browser class contain? And is it necessary that I also create one? – BrandNewDev Sep 27 '11 at 22:52
  • 1
    His `browser` class is probably just a simple one with properties relevant to a browser. You could create a class with the properties he uses to use his code as is, or you could just look at how he's getting the values, rather than how he's storing them. – George Duckett Sep 28 '11 at 07:12
  • please do not include unprofessional, rude words in your posts here. – Jeff Atwood Oct 03 '11 at 11:53
  • OK sorry. Just seems stupid what they've done. – BrandNewDev Oct 04 '11 at 00:49

1 Answers1

12

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();
hcb
  • 8,147
  • 1
  • 18
  • 17
  • 1
    What is the difference between checking that location and checking HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Uninstall? Aside from the obvious. – BrandNewDev Sep 27 '11 at 22:54
  • 3
    That would list all installed programs (that could be uninstalled) not just browsers. So you'd need a list of 'accepted' browsers to match against, with the potential to miss ones the user may have installed. – George Duckett Sep 28 '11 at 07:05
  • OK so StartMenuInternet is strictly browsers? I see. So browserKeys.GetSubKeyNames() takes the names and stores them in a string array do i just iterate through the array looking for "firefox" or something like that? The only reason I ask is because its going to take me a while to perfect the code to do that, I am a complete newbie so its going to be trial and error till i get it heh. Thanks. – BrandNewDev Sep 28 '11 at 07:51
  • You can put a linebreak on browserNames and look at the names you get on your machine. – hcb Sep 28 '11 at 07:57
  • Please mention the original post: http://www.rhizohm.net/irhetoric/post/2009/04/03/0a-Finding-All-Installed-Browsers-in-Windows-XP-and-Vista-ndash3b-beware-64bit!0a-.aspx – SepehrM Apr 28 '14 at 19:00
  • How do I find the executable path with these browser names? – Maiko Kingma Dec 28 '15 at 13:37