2013-05-30

Get Internet Explorer version using WMI StdRegProv

In Windows XP, you could get the version of Internet Explorer on a computer using the "\Applications\MicrosoftIE" namespace in this fragment of VBA: (To use this code in this article in your VBA project, include a reference to Microsoft WMI Scripting 1.2 Library.)
    Dim objSWbemLocator As SWbemLocator
    Dim objSWbemServices As SWbemServices, colSWbemObjectSet As SWbemObjectSet, objSWbemObject As SWbemObject, varValue As Variant

    Set objSWbemServices = objSWbemLocator.ConnectServer(strServer:=".", strNamespace:="\Applications\MicrosoftIE")
    Set colSWbemObjectSet = objSWbemServices.ExecQuery("Select * from MicrosoftIE_Summary")
    For objSWbemObject in colSWbemObjectSet
      Debug.Print objSWbemObject.Version
    Next objSWbemObject
The "\Applications\MicrosoftIE" namespace is not available after the introduction of Vista (and Windows 7), so the alternative is to examine the registry:
Const HKEY_LOCAL_MACHINE = &H80000002
...
    Dim objSWbemLocator As SWbemLocator
    Dim objSWbemServices As SWbemServices, objSWbemObject As SWbemObject, varValue As Variant

    Set objSWbemServices = objSWbemLocator.ConnectServer(strServer:=".", strNamespace:="\root\default")
    Set objSWbemObject = objSWbemServices.Get("StdRegProv")
    objSWbemObject.GetStringValue HKEY_LOCAL_MACHINE, "SOFTWARE\Microsoft\Internet Explorer\", "Version", varValue
    Debug.Print = varValue

No comments:

Post a Comment