Visual studio 检测Visual Studio许可证类型/分发通道

Visual studio 检测Visual Studio许可证类型/分发通道,visual-studio,registry,licensing,msdn,Visual Studio,Registry,Licensing,Msdn,关于如何使用PID(可在HKLM\SYSTEM\Setup\PID注册表项中找到)和ProductID(可在HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion中找到)检测Windows许可证类型和分销渠道,网络上有大量信息 但是,关于如何检测用于安装其他Microsoft产品的许可类型的信息非常少 也就是说,我需要确定哪些是使用MSDN订阅许可证安装的,哪些是使用其他许可证类型安装的 我通过分析产品GUID(在Uninstallregistry分支

关于如何使用PID(可在
HKLM\SYSTEM\Setup\PID
注册表项中找到)和ProductID(可在
HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion
中找到)检测Windows许可证类型和分销渠道,网络上有大量信息

但是,关于如何检测用于安装其他Microsoft产品的许可类型的信息非常少

也就是说,我需要确定哪些是使用MSDN订阅许可证安装的,哪些是使用其他许可证类型安装的

我通过分析产品GUID(在
Uninstall
registry分支中找到),找到了一些有关Office风格的信息:

但是,所有这些文章仅区分这些发布类型:

  • 0批量许可证
  • 1零售/原始设备制造商
  • 2审判
  • 5下载
此外,我找不到关于其他产品的任何可行信息。 也就是说,VisualStudio。。。(哪一个是我最感兴趣的)

为了澄清:我不需要获得许可证密钥(我在寻找所需信息时已经找到了几种检测方法),我只想检测安装应用程序使用的许可证类型。

要检测在哪个Visual Studio版本a(多IDE)加载项下运行,可以使用EnvDTE.DTE.RegistryRoot属性,该属性可以返回以下值:
对于Visual Studio 2005:软件\Microsoft\VisualStudio\8.0
对于Visual Studio 2008:软件\Microsoft\VisualStudio\9.0
要检测Visual Studio IDE的版本和子版本,可以使用IVsShell接口,使用Microsoft.VisualStudio.Shell.Interop.\uu VSSPROPID2.VSSPROPID\u SKUEdition和Microsoft.VisualStudio.Shell.Interop.\uu VSSPROPID2.VSSPROPID\u SubSKUEdition值调用其GetProperty方法。
注意:若要从外接程序获取服务,请参见如何:从外接程序获取Visual Studio服务;要了解如何从GAC引用程序集(如Microsoft.VisualStudio.Shell.Interop.dll),请参阅HOWTO:从外接程序引用GAC中的Visual Studio程序集。
返回的结果没有很好的文档记录,但以下示例加载项中提供了一些值:
导入系统
导入Microsoft.VisualStudio.CommandBars
导入可扩展性
进口环境
导入System.Runtime.InteropServices
导入Microsoft.VisualStudio.Shell.Interop
导入System.Windows.Forms
_
朋友接口IServiceProvider
_
函数QueryService(ByRef guidService作为Guid_
ByRef riid作为Guid,ByRef PPVOObject作为IntPtr)作为整数
端接口
公共类连接
实现IDTExtensibility2
私有枚举版本
SKUEdition\u None=0
SKU Express=500
SKU标准=&H3E8
SKU专业版=&H7D0
SKUEdition_AcademicProfessional=&H834
SKU学院学生=&H834
SKU学院学生MSDNAA=&H898
SKU企业版=&H8FC
SKUEdition\u图书=&H960
SKUEdition\u下载试用版=&H9C4
SKU企业版=&HBB8
结束枚举
私有枚举子版本
子版本\无=&H0
子版本\u VC=&H1
子版本_VB=&H2
子版本\u CSharp=&H4
SUBSKU建筑师=&H8
SUBSKU IDE=&H10
SubSKUEdition_JSharp=&H20
SUBSKU Web=&H40
SubSKUEdition\u TeamEditionDevelopers=&H80
结束枚举
公共函数GetService(ByVal serviceProvider作为对象,ByVal类型作为System.type)作为对象
返回GetService(serviceProvider,type.GUID)
端函数
公共函数GetService(ByVal serviceProvider作为对象,ByVal guid作为System.guid)作为对象
Dim objService As Object=无
作为IServiceProvider的Dim objIServiceProvider
作为IntPtr的Dim objIntPtr
Dim hr作为整数
Dim objSIDGuid作为Guid
作为Guid的Dim objIIDGuid
objSIDGuid=guid
objIIDGuid=objSIDGuid
objIServiceProvider=CType(服务提供者、IServiceProvider)
hr=objIServiceProvider.QueryService(objSIDGuid、objIIDGuid、objintpttr)
如果hr为0,则
System.Runtime.InteropServices.Marshal.ThroweExceptionForHR(hr)
否则,如果对象不等于(IntPtr.Zero),则
objService=System.Runtime.InteropServices.Marshal.GetObjectForIUnknown(OBJINTPTTR)
System.Runtime.InteropServices.Marshal.Release(OBJINTPTTR)
如果结束
返回对象服务
端函数
Public Sub OnConnection(ByVal应用程序作为对象,ByVal ConnectMode作为可扩展性。ext_ConnectMode_
ByVal AddInInt作为对象,ByRef自定义作为System.Array)_
实现Extensibility.IDTExtensibility2.OnConnection
作为DTE的Dim objDTE
Dim objService作为对象
作为IVsShell的暗淡对象shell
作为对象的Dim objValue=无
Dim eSKUEdition作为SKUEdition
Dim Esubsku版本作为Subsku版本
选择案例连接模式
案例ext_ConnectMode.ext_cm_启动后,ext_ConnectMode.ext_cm_启动
objDTE=DirectCast(应用程序,DTE)
objService=GetService(objDTE,GetType(IVsShell))
objivshell=CType(objService,IVsShell)
如果objivshell.GetProperty(_VSSPROPID2.VSSPROPID_SKUEdition,objValue)=0,则
eSKUEdition=CType(objValue,SKUEdition)
MessageBox.Show(eSKUEdition.ToString)
如果结束
如果objivshell.GetProperty(_VSSPROPID2.VSSPROPID_subskueedition,objValue)=0,则
eSubSKUEdition=CType(objValue,SubSKUEdition)
MessageBox.Show(eSubSKUEdition.ToString)
如果结束
结束选择
端接头
公共子OnAddInsUpdate(ByRef自定义为System.Array)_
伊姆河
Visual Studio 2010
The detection keys for Visual Studio are used both to detect if the product is installed and what service pack level is installed. As with previous versions, these keys and values are under HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\DevDiv\VS\Servicing.

Key HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\DevDiv\VS\Servicing\10.0\$(var.ProductEdition)\$(var.LCID)
Name    Install
Type    REG_DWORD (32-bit integer)
Data    0x00000001 (1)
The values for $(var.ProductEdition) include the following table. The for other products, this value corresponds to the ProductEdition property in the Property table of the Windows Installer package for that product. The locale IDs for $(Var.LCID) are listed here.

Visual Studio 2010 Ultimate      VSTSCore
Visual Studio 2010 Premium       VSTDCore
Visual Studio 2010 Professional  PROCore
Visual Studio 2010 Shell (Integrated)   IntShell
For Dev10 we have also added detection values to the edition keys so that you do not have to detect every single language for ever edition.

Key HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\DevDiv\VS\Servicing\10.0\$(var.ProductEdition)
Name    Install
Type    REG_DWORD (32-bit integer)
Data    0x00000001 (1)
These registry keys and values are also used to detect the service pack level. Instead of checking for the Name registry value, check the SP registry value. Ignore SPIndex; Microsoft uses this internally. In addition to the registry keys above, we also set a version-dependent registry value listed below.

Key HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\DevDiv\VS\Servicing\10.0
Name    SP
Type    REG_DWORD (32-bit integer)
Data    0x00000001 (1)
Keep in mind, however, that as with all shared resources the more shared a resource is the less accurate it may be. This is because there is no version policy for registry values and other resources that do not have versions like text files. If two languages were installed at different servicing pack levels – which is unsupported but possible – the value would be set by the last product to be installed or reinstalled (repaired).

For more information, see the Visual Studio 2010 detection system requirements. This also includes information to use the CompLocator in your Windows Installer package as an alternative to registry detection.
To detect which Visual Studio version a (multi-IDE) add-in is running under, you can use the EnvDTE.DTE.RegistryRoot property, which can return the following values:
For Visual Studio 2005: Software\Microsoft\VisualStudio\8.0
For Visual Studio 2008: Software\Microsoft\VisualStudio\9.0
To detect the edition and subedition of the Visual Studio IDE you can use the IVsShell interface, calling its GetProperty method with the Microsoft.VisualStudio.Shell.Interop.__VSSPROPID2.VSSPROPID_SKUEdition and Microsoft.VisualStudio.Shell.Interop.__VSSPROPID2.VSSPROPID_SubSKUEdition values.

Note: To get a service from an add-in, see HOWTO: Get a Visual Studio service from an add-in; and to know how to reference an assembly from the GAC (such as Microsoft.VisualStudio.Shell.Interop.dll), see HOWTO: Reference a Visual Studio assembly in the GAC from an add-in.

The returned results are not well documented but some values are provided in the following sample add-in:

Imports System
Imports Microsoft.VisualStudio.CommandBars
Imports Extensibility
Imports EnvDTE
Imports System.Runtime.InteropServices
Imports Microsoft.VisualStudio.Shell.Interop
Imports System.Windows.Forms



<ComVisible(True), ComImport(), Guid("6D5140C1-7436-11CE-8034-00AA006009FA"), _
InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIUnknown)> _
Friend Interface IServiceProvider
   <PreserveSig()> _
   Function QueryService(<InAttribute()> ByRef guidService As Guid, _
      <InAttribute()> ByRef riid As Guid, <OutAttribute()> ByRef ppvObject As IntPtr) As Integer
End Interface

Public Class Connect
   Implements IDTExtensibility2

   Private Enum SKUEdition
      SKUEdition_None = 0
      SKUEdition_Express = 500
      SKUEdition_Standard = &H3E8
      SKUEdition_Professional = &H7D0
      SKUEdition_AcademicProfessional = &H834
      SKUEdition_AcademicStudent = &H834
      SKUEdition_AcademicStudentMSDNAA = &H898
      SKUEdition_AcademicEnterprise = &H8FC
      SKUEdition_Book = &H960
      SKUEdition_DownloadTrial = &H9C4
      SKUEdition_Enterprise = &HBB8
   End Enum

   Private Enum SubSKUEdition
      SubSKUEdition_None = &H0
      SubSKUEdition_VC = &H1
      SubSKUEdition_VB = &H2
      SubSKUEdition_CSharp = &H4
      SubSKUEdition_Architect = &H8
      SubSKUEdition_IDE = &H10
      SubSKUEdition_JSharp = &H20
      SubSKUEdition_Web = &H40
      SubSKUEdition_TeamEditionDevelopers = &H80
   End Enum

   Public Function GetService(ByVal serviceProvider As Object, ByVal type As System.Type) As Object
      Return GetService(serviceProvider, type.GUID)
   End Function

   Public Function GetService(ByVal serviceProvider As Object, ByVal guid As System.Guid) As Object

      Dim objService As Object = Nothing
      Dim objIServiceProvider As IServiceProvider
      Dim objIntPtr As IntPtr
      Dim hr As Integer
      Dim objSIDGuid As Guid
      Dim objIIDGuid As Guid

      objSIDGuid = guid
      objIIDGuid = objSIDGuid
      objIServiceProvider = CType(serviceProvider, IServiceProvider)

      hr = objIServiceProvider.QueryService(objSIDGuid, objIIDGuid, objIntPtr)
      If hr <> 0 Then
         System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(hr)
      ElseIf Not objIntPtr.Equals(IntPtr.Zero) Then
         objService = System.Runtime.InteropServices.Marshal.GetObjectForIUnknown(objIntPtr)
         System.Runtime.InteropServices.Marshal.Release(objIntPtr)
      End If

      Return objService

   End Function

   Public Sub OnConnection(ByVal Application As Object, ByVal ConnectMode As Extensibility.ext_ConnectMode, _
      ByVal AddInInst As Object, ByRef custom As System.Array) _
      Implements Extensibility.IDTExtensibility2.OnConnection

      Dim objDTE As DTE
      Dim objService As Object
      Dim objIVsShell As IVsShell
      Dim objValue As Object = Nothing
      Dim eSKUEdition As SKUEdition
      Dim eSubSKUEdition As SubSKUEdition

      Select Case ConnectMode

         Case ext_ConnectMode.ext_cm_AfterStartup, ext_ConnectMode.ext_cm_Startup

            objDTE = DirectCast(Application, DTE)
            objService = GetService(objDTE, GetType(IVsShell))
            objIVsShell = CType(objService, IVsShell)

            If objIVsShell.GetProperty(__VSSPROPID2.VSSPROPID_SKUEdition, objValue) = 0 Then
               eSKUEdition = CType(objValue, SKUEdition)
               MessageBox.Show(eSKUEdition.ToString)
            End If

            If objIVsShell.GetProperty(__VSSPROPID2.VSSPROPID_SubSKUEdition, objValue) = 0 Then
               eSubSKUEdition = CType(objValue, SubSKUEdition)
               MessageBox.Show(eSubSKUEdition.ToString)
            End If

      End Select

   End Sub

   Public Sub OnAddInsUpdate(ByRef custom As System.Array) _
      Implements Extensibility.IDTExtensibility2.OnAddInsUpdate

   End Sub

   Public Sub OnBeginShutdown(ByRef custom As System.Array) _
      Implements Extensibility.IDTExtensibility2.OnBeginShutdown

   End Sub

   Public Sub OnDisconnection(ByVal RemoveMode As Extensibility.ext_DisconnectMode, _
      ByRef custom As System.Array) Implements Extensibility.IDTExtensibility2.OnDisconnection

   End Sub

   Public Sub OnStartupComplete(ByRef custom As System.Array) _
      Implements Extensibility.IDTExtensibility2.OnStartupComplete

   End Sub

End Class
To detect whether a specific Visual Studio package is installed or not, you can use the IsPackageInstalled method of the IVsShell interface, which receives the Guid of the package.
Detecting installed Visual Studio Service Packs

Visual Studio uses the following Windows registry entries to track the installed service packs for the several versions (2005, 2008), editions (Standard, Professional, etc.) and languages (English, Spanish, etc.):

HKEY_LOCAL_MACHINE\Software\Microsoft\DevDiv\VS\Servicing\<version>\<edition>\<localeId>

where <version> and <edition> where explained in a previous section of this article and <localeId> is 1033 for English, 3082 for Spanish, etc.

For example, when Visual Studio 2005 Team Edition for Developers has SP1 installed, the value of the "SP" registry entry of HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\DevDiv\VS\Servicing\8.0\VSTD\1033 is set to 1.

To know the service at general level (without taking into account the edition and language) you can use the "SP" registry entry under the registry key:

HKEY_LOCAL_MACHINE\Software\Microsoft\DevDiv\VS\Servicing\<version>