Determine if MOSS is installed by checking the Registry key

Today I found a post that explains a way to determine if MOSS is installed by checking on the existence of certain folders. Another way is to check on the existence of its the registry key.

image

The RegistryKey class is located in the Microsoft.Win32 namespace of the mscorlib.dll.

bool isMossInstalled = false;
string keyname = @"SOFTWARE\Microsoft\Office Server\12.0";
using (RegistryKey key = Registry.LocalMachine.OpenSubKey(keyname))
{
   if (key != null)
   {
       string version = key.GetValue("BuildVersion") as string;
       if (version != null)
       {
           Version buildVersion = new Version(version);
           if (buildVersion.Major == 12)
           {
              isMossInstalled = true;
           }
        }
   }
}

In a similar way you can determine if WSS is installed. In the registry you can find the following information:

image

Translated into code:

bool isWssInstalled = false;
string keyname = @"SOFTWARE\Microsoft\Shared Tools\Web Server Extensions\12.0";
using (RegistryKey key = Registry.LocalMachine.OpenSubKey(keyname))
{
  if (key != null)
  {
    object wssvalue = key.GetValue("SharePoint");
    if (wssvalue != null && wssvalue.Equals("Installed"))
    {
      isWssInstalled = true;
    }
  }
}