Solved

get installed web browsers list using c#

Posted on 2011-03-24
12
2,502 Views
Last Modified: 2012-05-11
get installed web browsers list using c#
0
Comment
Question by:cgt_puneetrao
12 Comments
 
LVL 7

Accepted Solution

by:
Gene_Cyp earned 167 total points
Comment Utility
In Windows all of the installed applications have a key in the HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths registry key. One solution would be to iterate over all the entries in this key and see if they match the names of your supported browsers.

Once you've got the registry keys for each browser, you can then get the Path value of each key, and see if the executable file exists in the specified path.

One thing to note is that on 64-bit versions of Windows, 32-bit apps are listed in the HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\App Paths.



For example:

Firefox's path is typically as follows:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\firefox.exe\

with two registry keys:

(Default): C:\Program Files\Mozilla Firefox\firefox.exe
Path: C:\Program Files\Mozilla Firefox


Inter Explorer's example:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\iexplorer.exe\

with two registry keys:

(Default): C:\Program Files\Internet Explorer\iexplorer.exe
Path: C:\Program Files\Internet Explorer;
0
 
LVL 7

Expert Comment

by:Gene_Cyp
Comment Utility
If you don't know how to translate what I said above into actual code, then check the following link:

http://www.dreamincode.net/code/snippet1995.htm




Note, if you just want to open a URL, type in the following:

System.Diagnostics.Process.Start("http://www.microsoft.com");


0
 
LVL 7

Expert Comment

by:Gene_Cyp
Comment Utility
Since it's not included in that snippet code, to launch the application you can do the following:

Say you found Chrome is one of the browsers, you can define the selected browser to launch based on a pre-selection by your interface and launch it as follows:


try
{
Process.Start("chrome", url);
}
catch
{
 // exception code goes here
}
0
 
LVL 7

Assisted Solution

by:dimaj
dimaj earned 167 total points
Comment Utility
I've written a blog entry about this using JScript under TestComplete and I think it might be very helpful to you. Here's my post: http://blog.dimaj.net/2011/02/howto-find-applications-install-path-with-jscript-using-windows-registry/

Basically I iterate over the uninstall registry entries and find a string you are searching for.

Hope this helps.
0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
LVL 15

Assisted Solution

by:Russell_Venable
Russell_Venable earned 166 total points
Comment Utility
You will need to look at these keys each one is for a different typo of processor. Browser developers are told to place there browser in this key. So just iterating through through these keys will give you your answer without all the need of sorting through all your applications.

HKEY_LOCAL_MACHINE\SOFTWARE\Clients\StartMenuInternet for x86

HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Clients\StartMenuInternet for x64

Open in new window


I have written some code for you to demonstrate this.
using System;
using Microsoft.Win32;

class registery
{
    static void Main()
    {

        //Check if your using x64 system first if return is null your on a x86 system.
        RegistryKey browserKeys = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\WOW6432Node\Clients\StartMenuInternet");
        if (browserKeys == null)
            browserKeys = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Clients\StartMenuInternet");

        // Lets get our keys!
        string[] browserNames = browserKeys.GetSubKeyNames();
        // Loop through all the subkeys for the information you want then display it on the console.
        for (int i = 0; i < browserNames.Length; i++)
        {
            // Initialise our class
            Browser browser = new Browser();
            RegistryKey browserKey = browserKeys.OpenSubKey(browserNames[i]);
            browser.Name = (string)browserKey.GetValue(null);
            RegistryKey browserKeyPath = browserKey.OpenSubKey(@"shell\open\command");
            browser.Path = (string)browserKeyPath.GetValue(null);
            RegistryKey browserIconPath = browserKey.OpenSubKey(@"DefaultIcon");
            browser.IconPath = (string)browserIconPath.GetValue(null);
            Console.WriteLine("Name: {0}\r\nPath: {1}\r\nIconPath: {2}", browser.Name, browser.Path, browser.IconPath);
        }
    }
}

class Browser
{
    // Create Accessors to hold our info in this class.
    public string Name
    {
        get;
        set;
    }
    public string Path
    {
        get;
        set;
    }
    public string IconPath
    {
        get;
        set;
    }
}

Open in new window

0
 

Author Comment

by:cgt_puneetrao
Comment Utility
I've requested that this question be deleted for the following reason:

not required
0
 
LVL 15

Expert Comment

by:Russell_Venable
Comment Utility
The correct way to find the installed browsers as given by Microsoft in the .NET language was posted with a working example of correct syntax and usage.

 Http:#a35218323 is a working  correct solution along with microsofts suggested registery enteries. The example goes beyond what is required here. You can separate as needed. This function is also faster and more direct then taking the time to code a filter for the uninstall list.

How is this not required when .NET engineers specifically point this out? Curious to see a answer. :)
0
 
LVL 7

Expert Comment

by:Gene_Cyp
Comment Utility
The combination of my three posts - even though i say it myself - provide a solution to his problem. From how to get them to how to call them.
0
 
LVL 15

Expert Comment

by:Russell_Venable
Comment Utility
This was intended for his problem. When you don't state your problem while posting on here and expect someone to give you the answer to solve the problem that lies in your head and not posted for suggestion. It's not feasible nor comprehend-able to give a full personalized answer for a problem that was never stated and described, nor followed up on.

As a software developer, You have to abide by standards. Depending on what kind of system is decided upon to be supported for the project. Considering a good majority of develops on the .NET Environment use windows, It makes perfect sense to go with a Microsoft solution.

The example given here shows how to grab the entry's for each browser installed. Considering each professionally available browser that has been professionally developed goes by professional standards and thus goes by the method provided. If there is confusion in this method. I would seriously suggest going back to the basics and relearning and taking a trip to MSDN to get needed support on well known API structure and calling conventions.

The example itself is not personalized as there was no need to personalize this example. The reason for the example was to show usage of the registry key provided not give a personally defined "I coded a working project for you, here you go" its not how this works and extracting the information in a useful way. I don't see why you would need to show that the browser is executable... You can simply set a break point in the software at the variable that is storing the location in the array, parse results as needed and watch for a correct/expected value as you should be doing in the first place.

If the user has a need to do this on a client-side(aka: ASP,PHP, etc) interpreted language level I would suggest that you use a solution as stated with dimaj's solution, but changing the registry key to use StartMenuInternet. The method of %AppPath% is intended for storing user profile information and iterating through uninstall or AppPath even though it may work is trivial to use when there is already a method made specifically for this purpose. This is re-inventing the wheel and elongates the process you go through to make things work properly, especially when you are just using it to just list browsers. It is also off-topic as it is not a C# solution. You will run into a lot of problems by not looking up the correct API usage for development. This is coming from a professional stand point may I tell you. This will give you less problems and it is assured that it will work best for you and as intended. It is very important not to overlook these methods it will make you a better programmer and get you to think not only inside the box with detail and sharpness, but will also help you get used to API used and how it was developed to easy the burden of coding for developers when used properly (yes, they had that in mind!) ;)
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Article by: Ivo
Anonymous Types in C# by Ivo Stoykov Anonymous Types are useful when  we do not need to follow usual work-flow -- creating object of some type, assign some read-only values and then doing something with them. Instead we can encapsulate this read…
Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now