Tuesday, July 13, 2010

How to check the Visual Studio 2010 edition from code

In my SqlCeToolBox add-in, I only expose some features if the user has Visual Studio Premium or higher, as I depend on some of the Data Dude tools.

The code to do this looks like this, notice the RegistryView option on the OpenBaseKey method. This ensures that this code works on both x64 and x86 based registries.

public static bool IsPremiumOrUltimate()
{
// From http://blogs.msdn.com/b/heaths/archive/2010/05/04/detection-keys-for-net-framework-4-0-and-visual-studio-2010.aspx
//Key HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\DevDiv\VS\Servicing\10.0\$(var.ProductEdition)\$(var.LCID)
//The values for $(var.ProductEdition) include the following table.
//Visual Studio 2010 Ultimate VSTSCore
//Visual Studio 2010 Premium VSTDCore
//Visual Studio 2010 Professional PROCore
//Visual Studio 2010 Shell (Integrated) IntShell
using (var key = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32))
{

var ultimateKey = key.OpenSubKey(@"SOFTWARE\Microsoft\DevDiv\VS\Servicing\10.0\VSTSCore");
if (ultimateKey != null)
return true;

var premiumKey = key.OpenSubKey(@"SOFTWARE\Microsoft\DevDiv\VS\Servicing\10.0\VSTDCore");
if (premiumKey != null)
return true;
}
return false;


}



No comments: