How to get a list of installed OLE DB providers?

好久不见. 提交于 2020-05-25 09:01:52

问题


Microsoft Excel allows import of data from "Other Sources". One of the options is to use an OLE DB provider.

How to get a list of available OLE DB providers?


回答1:


If you have powershell available, just paste this into a powershell command prompt:

foreach ($provider in [System.Data.OleDb.OleDbEnumerator]::GetRootEnumerator())
{
    $v = New-Object PSObject        
    for ($i = 0; $i -lt $provider.FieldCount; $i++) 
    {
        Add-Member -in $v NoteProperty $provider.GetName($i) $provider.GetValue($i)
    }
    $v
}

Credits and more advanced usage: http://dbadailystuff.com/list-all-ole-db-providers-in-powershell




回答2:


I am answering my own question because this was harder to find that I expected. Google-fu could only answer part of my question; I needed to synthesize information from various blog entries and official documentation.

Below is VBScript you can copy/paste into a text file and run on Windows. You do not need local admin rights to run this version.

Depending on the size of your registry and speed on your CPU, it may take up to one minute to run. The result is a message box with text that can be copied to the clipboard with Ctrl+C.

Primary reference: https://sysmod.wordpress.com/2014/07/11/vbscript-to-list-installed-oledb-providers/

'List of installed OLEDB providers on local computer
Option Explicit
Const HKEY_CLASSES_ROOT     = &H80000000
Const HKEY_CURRENT_USER     = &H80000001
Const HKEY_LOCAL_MACHINE    = &H80000002
Const HKEY_USERS        = &H80000003
Const HKEY_CURRENT_CONFIG   = &H80000005

Dim OutText, strComputer, objRegistry
Dim num
Dim ProgIdDict

strComputer = "."
Set objRegistry = GetObject("winmgmts:\\" & strComputer & "\root\default:StdRegProv")
OutText = "Note: Strike Ctrl+C to copy full text to clipboard"
Num = 1
Set ProgIdDict = CreateObject("Scripting.Dictionary")

' I discovered these registrations can appear in three different places.
' Use ProgIdDict to prevent dupes in the output
Append objRegistry, HKEY_CLASSES_ROOT, "HKEY_CLASSES_ROOT", "CLSID", ProgIdDict, Num, OutText
Append objRegistry, HKEY_LOCAL_MACHINE, "HKEY_LOCAL_MACHINE", "SOFTWARE\Classes\CLSID", ProgIdDict, Num, OutText
Append objRegistry, HKEY_LOCAL_MACHINE, "HKEY_LOCAL_MACHINE", "SOFTWARE\Classes\Wow6432Node\CLSID", ProgIdDict, Num, OutText

Sub Append(ByVal objRegistry, ByVal HKEYConstant, ByVal HKEYConstantStr, ByVal KeyPrefixStr, ByVal ProgIdDict, ByRef Num, ByRef OutText)

    Dim Key, arrKeys
    Dim strKeyPath, strValue, uValue

    objRegistry.enumKey HKEYConstant, KeyPrefixStr, arrKeys

    for each key in arrKeys

        strKeyPath = KeyPrefixStr & "\" & key

        ' if key exists...
        ' I noticed something weird where non-MSOLAP entries use the first style,
        ' and MSOLAP entries use the second style.
        If 0 = objRegistry.GetDWordValue(HKEYConstant, strKeyPath, "OLEDB_SERVICES", uValue) _
        Or 0 = objRegistry.GetDWordValue(HKEYConstant, strKeyPath & "\OLEDB_SERVICES", "", uValue) _
        Then
            objRegistry.GetStringValue HKEYConstant,strKeyPath & "\ProgID","",strValue
            If Not ProgIdDict.Exists(strValue) _
            Then
                ProgIdDict.Add strValue, strValue
                OutText=OutText & vbcrlf & vbcrlf
                'get the (Default) value which is the name of the provider
                objRegistry.GetStringValue HKEYConstant,strKeyPath,"",strValue
                OutText=OutText & num & ") " & strValue & vbcrlf & "Key: \\" & HKEYConstantStr & "\" & KeyPrefixStr & "\" & key
                ' and the expanded description
                objRegistry.GetStringValue HKEYConstant,strKeyPath & "\OLE DB Provider","",strValue
                OutText=OutText & vbcrlf & "OLE DB Provider: " & strValue
                objRegistry.GetStringValue HKEYConstant,strKeyPath & "\ProgID","",strValue
                OutText=OutText & vbcrlf & "ProgID: " & strValue
                objRegistry.GetStringValue HKEYConstant,strKeyPath & "\VersionIndependentProgID","",strValue
                OutText=OutText & vbcrlf & "VersionIndependentProgID: " & strValue
                num = 1 + num
            End If
        end if
    next

End Sub

Wscript.Echo OutText



回答3:


Another solution using PowerShell, this time leveraging .NET code (credit to jrich523.wordpress.com).

Plug this into a PowerShell console:

(New-Object system.data.oledb.oledbenumerator).GetElements()

Produces output like this:

SOURCES_NAME        : SQLOLEDB Enumerator
SOURCES_PARSENAME   : {DFA22B8E-E68D-11d0-97E4-00C04FC2AD98}
SOURCES_DESCRIPTION : Microsoft OLE DB Enumerator for SQL Server
SOURCES_TYPE        : 2
SOURCES_ISPARENT    : False
SOURCES_CLSID       : {DFA22B8E-E68D-11d0-97E4-00C04FC2AD98}



回答4:


OLEDB provides a class that will enumerate all OLE DB providers for you.

Microsoft OLE DB Root Enumerator🕗

  • ProgID: "MSDAENUM"
  • clsid: {c8b522d0-5cf3-11ce-ade5-00aa0044773d}
  • CLSID_OLEDB_ENUMERATOR (from msdaguid.h in the sdk)

Unfortunately you cannot access it through ADO (ADO is a friendly wrapper around OLE DB, and the MSDAENUM class does not support some interfaces that ADO requires that the OLEDB provider support). This means you would have no choice but to talk to it, and it's IRowset directly.

And the OLE DB api is... merciless.




回答5:


I had an issue where Steinar Herland's powershell script wasn't finding my oledb provider. I wrote a little c# program that did though.

using System.Data.OleDb;
var oleEnum = new OleDbEnumerator(); var elems = oleEnum.GetElements(); if (elems != null && elems.Rows != null) foreach (System.Data.DataRow row in elems.Rows) if (!row.IsNull("SOURCES_NAME") && row["SOURCES_NAME"] is string) Console.WriteLine(row["SOURCES_NAME"]);



来源:https://stackoverflow.com/questions/37849262/how-to-get-a-list-of-installed-ole-db-providers

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!