How To: Detect the Installed SKU of SharePoint 2010

Applies to: SharePoint Server 2010

If the behavior of your custom application depends on the installed SKU of Microsoft SharePoint Server 2010, you can determine which SKU of SharePoint Server 2010 is installed locally by using the code sample in this topic.

Detecting the Installed SKU of SharePoint Server 2010 by Using Code

The following code sample demonstrates how to retrieve the registry key of the installed SKU of SharePoint Server 2010 and of other Microsoft Office server products, and how to match the SKU with a hash table that stores the names and keys for all of the known SKUs of these products. The console output displays the name of the installed SKU.

using System;
using System.Collections;
using Microsoft.Win32;


namespace GetInstalledSharePointSku
{
    class Program
    {
        internal static Hashtable _products;

        public static Hashtable SharePointProducts
        {
            get 
            {
                if (_products == null)
                {
                    _products = new Hashtable();

                    _products.Add("BEED1F75-C398-4447-AEF1-E66E1F0DF91E", "SharePoint Foundation 2010");
                    _products.Add("1328E89E-7EC8-4F7E-809E-7E945796E511", "Search Server Express 2010");

                    _products.Add("B2C0B444-3914-4ACB-A0B8-7CF50A8F7AA0", "SharePoint Server 2010 Standard Trial");
                    _products.Add("3FDFBCC8-B3E4-4482-91FA-122C6432805C", "SharePoint Server 2010 Standard");
                    _products.Add("88BED06D-8C6B-4E62-AB01-546D6005FE97", "SharePoint Server 2010 Enterprise Trial");
                    _products.Add("D5595F62-449B-4061-B0B2-0CBAD410BB51", "SharePoint Server 2010 Enterprise");

                    _products.Add("BC4C1C97-9013-4033-A0DD-9DC9E6D6C887", "Search Server 2010 Trial");
                    _products.Add("08460AA2-A176-442C-BDCA-26928704D80B", "Search Server 2010");

                    _products.Add("84902853-59F6-4B20-BC7C-DE4F419FEFAD", "Project Server 2010 Trial");
                    _products.Add("ED21638F-97FF-4A65-AD9B-6889B93065E2", "Project Server 2010");

                    _products.Add("926E4E17-087B-47D1-8BD7-91A394BC6196", "Office Web Companions 2010");
                }
                
                return _products;
            }
        }

        private const String SharePointProductsRegistryPath = @"SOFTWARE\Microsoft\Shared Tools\Web Server Extensions\14.0\WSS\InstalledProducts\";

        static void Main(string[] args)
        {
            try
            {
                //Open the registry key in read-only mode.
                using (RegistryKey key = Registry.LocalMachine.OpenSubKey(SharePointProductsRegistryPath, false))
                {
                    //Get all of the installed product code/SKUId pairs.
                    foreach (String value in key.GetValueNames())
                    {
                        try
                        {
                            //Get the SKUId and see whether it is a known product.
                            String SKUId = key.GetValue(value) as String;

                            if (SharePointProducts[SKUId] != null)
                            {
                                Console.WriteLine("Product Installed: {0}", SharePointProducts[SKUId]);
                            }
                            else
                            {
                                Console.WriteLine("Unknown Product: {0}", SKUId);
                            }
                        }
                        catch (Exception e)
                        {
                            Console.WriteLine("Could not read key exception was {0}", e.Message);
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("Could not open key exception was {0}", e.Message);
            }
            Console.Read();
        }
    }
}

See Also

Concepts

Enterprise Development with SharePoint Server 2010

Other Resources

What's New in SharePoint Server 2010

SharePoint Developer Team Blog

SharePoint Stack Exchange