Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

get installed web browsers list using c#

Posted on 2011-03-24
12
Medium Priority
?
2,863 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 668 total points
ID: 35206000
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
ID: 35206137
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
ID: 35206169
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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 7

Assisted Solution

by:dimaj
dimaj earned 668 total points
ID: 35207241
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
 
LVL 15

Assisted Solution

by:Russell_Venable
Russell_Venable earned 664 total points
ID: 35218323
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
ID: 35965038
I've requested that this question be deleted for the following reason:

not required
0
 
LVL 15

Expert Comment

by:Russell_Venable
ID: 36031195
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
ID: 36031552
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
ID: 36031697
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…

971 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