none
Get a list of all browsers installed and their versions from remote desktop RRS feed

  • Question

  • Hello All,

    I writing C# code to pull the names of the browsers and their versions from remote desktops as shown below. I am partially successful and I am getting the browser names. However, I need help to pull the browser versions. Please help.

       foreach (string s in hostNames)
                {
                  
    
                    ManagementScope scope = new ManagementScope(@"\\" + s + "\\root\\cimv2", options);
                    ManagementPath mypath = new ManagementPath("StdRegProv");
                    ManagementClass wmiRegistry = new ManagementClass(scope, mypath, null);
                   
                    List<string> programs = new List<string>();
    
                    string softwareRegLoc = @"SOFTWARE\WOW6432Node\Clients\StartMenuInternet";
    
                    ManagementClass registry = new ManagementClass(scope, new ManagementPath("StdRegProv"), null);
                    ManagementBaseObject inParams = registry.GetMethodParameters("EnumKey");
                    inParams["hDefKey"] = 0x80000002;//HKEY_LOCAL_MACHINE
                    inParams["sSubKeyName"] = softwareRegLoc;
    
                    // Read Registry Key Names 
                    ManagementBaseObject outParams = registry.InvokeMethod("EnumKey", inParams, null);
                    string[] programGuids = outParams["sNames"] as string[];
                    string str = null;
                    foreach (string subKeyName in programGuids)
                    {
                        inParams = registry.GetMethodParameters("GetStringValue");
                        inParams["hDefKey"] = 0x80000002;//HKEY_LOCAL_MACHINE
                        inParams["sSubKeyName"] = softwareRegLoc + @"\" + subKeyName;
    
                        outParams = registry.InvokeMethod("GetStringValue", inParams, null);
    
                        if (outParams.Properties["sValue"].Value != null)
                        {
                            string softwareName = outParams.Properties["sValue"].Value.ToString();
                            str += softwareName + " | ";
                        }
                    }
    
    
    
                }

    Monday, July 23, 2018 6:10 PM

All replies

  • Hi SharePoint2016,

    Thank you for posting here.

    For your question, please try the code below.

    using Microsoft.Win32;
    using System;
    using System.Collections.Generic;
    using System.Diagnostics;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    
    namespace ConsoleApp
    {
        class GetAllInstalledBrowsers
        {
            static void Main(string[] args)
            {
                foreach (Browser browser in GetBrowsers())
                {
                    Console.WriteLine(string.Format("{0}: \n\tPath: {1} \n\tVersion: {2} \n\tIcon: {3}", browser.Name, browser.Path, browser.Version, browser.IconPath));
                }
                Console.ReadKey();
            }
            public static List<Browser> GetBrowsers()
            {
                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();
                var browsers = new List<Browser>();
                for (int i = 0; i < browserNames.Length; i++)
                {
                    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).ToString().StripQuotes();
                    RegistryKey browserIconPath = browserKey.OpenSubKey(@"DefaultIcon");
                    browser.IconPath = (string)browserIconPath.GetValue(null).ToString().StripQuotes();
                    browsers.Add(browser);
                    if (browser.Path != null)
                        browser.Version = FileVersionInfo.GetVersionInfo(browser.Path).FileVersion;
                    else
                        browser.Version = "unknown";
                }
                return browsers;
            }
        }
        internal static class Extensions
        {
            ///
            /// if string begins and ends with quotes, they are removed
            ///
            internal static String StripQuotes(this String s)
            {
                if (s.EndsWith("\"") && s.StartsWith("\""))
                {
                    return s.Substring(1, s.Length - 2);
                }
                else
                {
                    return s;
                }
            }
        }
    
    
        class Browser
        {
            public string Name { get; set; }
            public string Path { get; set; }
            public string IconPath { get; set; }
            public string Version { get; set; }
        }
    }
    
    
    

    Best Regards,

    Wendy


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, July 24, 2018 6:59 AM
    Moderator
  • Thanks Wendy for the response. The code works for local machine whereas I am looking for a remote server.

    Knowledge is power.Information is wealth.

    Tuesday, July 24, 2018 10:09 PM
  • Someone please reply to me.

    Knowledge is power.Information is wealth.

    Tuesday, July 31, 2018 5:30 PM