Jump to content

Getting ODBC driver info


 Share

Recommended Posts

I've been trying to figure out a way to query a machine on the network to get the installed programs and drivers available on the machine. I was able to figure out the programs part but I'm struggling with the ODBC Driver list. This is what I've done and it works without any notable issues:

Func GetMachineInstalls($strComputer="localhost")
    local $aReturn[0][2],$colItems
    $wbemFlagReturnImmediately = 0x10
    $wbemFlagForwardOnly = 0x20
    $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2")
    $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_Product", "WQL", _
                                              $wbemFlagReturnImmediately + $wbemFlagForwardOnly)

    If IsObj($colItems) then
       For $objItem In $colItems
          $sName = $objItem.Name
          $sVersion = $objItem.Version
          _ArrayAdd($aReturn,$sName&"|"&$sVersion,0)
       Next
       Return $aReturn
    Else
       return -1
    Endif
EndFunc

 


I tracked down this article that talks about how to do this. This is the block I need to modify to work in autoit:

Const HKEY_LOCAL_MACHINE = &H80000002
strComputer = “.”
Set objRegistry = GetObject(“winmgmts:\\” & strComputer & “\root\default:StdRegProv”)
strKeyPath = “SOFTWARE\ODBC\ODBCINST.INI\ODBC Drivers”
objRegistry.EnumValues HKEY_LOCAL_MACHINE, strKeyPath, arrValueNames, arrValueTypes
For i = 0 to UBound(arrValueNames)
    strValueName = arrValueNames(i)
    objRegistry.GetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue
    Wscript.Echo arrValueNames(i) & ” — ” & strValue
Next

Does anyone understand the block above and how I can adapt it to work? I'm also trying to figure out how to get the OS Type(32/64)/name/version using similar logic if anyone is aware of a UDF.

Edited by Jewtus
Link to comment
Share on other sites

The WMI method or native Reg* Funcs should be able to do what you want.  One may perform "better" than the other...not sure, and I'm not at a place where I can test; but I do recall the Reg funcs support remote machines.  Otherwise, it's pretty trivial to adapt the vb code to AutoIt.  You are already half way there with your working WMI example.  There also appear to be ODBC WMI classes, but I'm not as familiar with them.

The Win32_OperatingSystem WMI class seems to have the OS info you need:
OSArchitecture
Caption
Version
BuildNumber
OperatingSystemSKU
 

Link to comment
Share on other sites

Check "ScriptoMatic" in the Example Scripts forum. This tool generates AutoIt code for you to query WMI.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

20 minutes ago, water said:

Check "ScriptoMatic" in the Example Scripts forum. This tool generates AutoIt code for you to query WMI.

How is it that you always have the droids I'm looking for?

Thanks a lot all, This will be very helpful. I'll share my script when I'm finished.

Link to comment
Share on other sites

Ok, so I'm a little confused... I used scriptomatic to generate some code and tweaked it to make it fit into what I already build but I'm not actually getting back any values:

 

$wbemFlagReturnImmediately = 0x10
$wbemFlagForwardOnly = 0x20
$colItems = ""
$strComputer = "localhost"

$objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2")
$colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_ODBCDriverSpecification", "WQL", _
                                          $wbemFlagReturnImmediately + $wbemFlagForwardOnly)
If IsObj($colItems) then
   For $objItem In $colItems
      ConsoleWrite($objItem.Driver& @CRLF)
      ConsoleWrite($objItem.Description& @CRLF)
      ConsoleWrite($objItem.Name& @CRLF)
      ConsoleWrite($objItem.Version & @CRLF)
      ConsoleWrite("=========================="& @CRLF)
   Next
Endif

When I run this, the objects are there in the $colItems, but nothing gets printed to the console. I checked the data types and the fields I'm grabbing are all strings and I'm using the correct namespace... 

 

I tried a few things out of scriptomatic and I had the same results (nothing writes to the console).

 

Anyone know what I'm doing wrong?

 

EDIT:

This one works but not the ODBC one

$wbemFlagReturnImmediately = 0x10
$wbemFlagForwardOnly = 0x20
$colItems = ""
$strComputer = "localhost"

$objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2")
$colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_OperatingSystem", "WQL", _
                                          $wbemFlagReturnImmediately + $wbemFlagForwardOnly)
If IsObj($colItems) then
   For $objItem In $colItems
      ConsoleWrite($objItem.OSArchitecture& @CRLF)
      ConsoleWrite($objItem.Caption& @CRLF)
      ConsoleWrite($objItem.Version& @CRLF)
      ConsoleWrite($objItem.BuildNumber& @CRLF)
      ConsoleWrite($objItem.OperatingSystemSKU & @CRLF)
      ConsoleWrite("=========================="& @CRLF)
   Next
Endif

 

Edited by Jewtus
Link to comment
Share on other sites

I also get no results from the ODBC WMI query, but do get (some) data using the registry method.  If the registry has the data you need/want, then it may be the better way to go.

 

Link to comment
Share on other sites

I've been trying to figure out how to do the registry method, but I'm grasping at straws (a lot of this WMI and installed software stuff is new to me).

If I do this:

$sVar = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\ODBC\ODBCINST.INI\ODBC Drivers","")

I get a result, but I'm not sure how to pull the "Name" from the registry.

I feel like this is a really simple step I'm missing. 

Link to comment
Share on other sites

@water you forgot about ado.au3 ?

; #FUNCTION# ====================================================================================================================
; Name ..........: _ADO_GetProvidersList
; Description ...: This tool lists all available providers installed on the computer.
; Syntax ........: _ADO_GetProvidersList()
; Parameters ....: None
; Return values .: $aResult - a list of all available providers installed on the computer
; Author ........: water
; Modified ......: mLipok
; Remarks .......: based on: _ADO_OLEDBProvidersList
; Related .......:
; Link ..........: https://www.autoitscript.com/wiki/ADO_Tools
; Example .......: No
; ===============================================================================================================================
Func _ADO_GetProvidersList()
....
....
....

 

Edited by mLipok

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST APIErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) * Show_Macro_Values.au3 *

 

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * 

OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskSchedulerIE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related:How to get reference to PDF object embeded in IE * IE on Windows 11

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

I also encourage you to check awesome @trancexx code:  * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuffOnHungApp handlerAvoid "AutoIt Error" message box in unknown errors  * HTML editor

winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2023-04-24

Link to comment
Share on other sites

@mLipok I took a look at that script and It does execute and pull back OLE DB providers, but I need ODBC providers.  I made some minor tweaks to it to see if I could adapt it, but I don't know enough about registry stuff.

I tried this, but I'm getting no results:

 

EDIT: I put the wrong HK ref in so I fixed it and the progress bar gets stuck at 0%

Func _ADO_GetProvidersList()
    Local $sKey = "HKLM\SOFTWARE\ODBC\ODBCINST.INI\ODBC Drivers" ; HKLM not HKMH
    Local $iIndexReg = 1, $iIndexResult = 0
    Local $iMax = 100000, $iMin = 1, $iPrevious = $iMin, $iCurrent = $iMax / 2
    Local $aResult[200][3]

    ProgressOn("", "Processing the Registry", "", Default, Default, $DLG_MOVEABLE)

    ; Count the number of keys
    While 1
        RegEnumKey($sKey, $iCurrent)
        If @error = -1 Then ; Requested subkey (key instance) out of range
            $iMax = $iCurrent
            $iCurrent = Int(($iMin + $iMax) / 2)
            $iPrevious = $iMax
        Else
            If $iPrevious <= ($iCurrent + 1) And $iPrevious >= ($iCurrent - 1) Then ExitLoop
            $iMin = $iCurrent
            $iCurrent = Int(($iMin + $iMax) / 2)
            $iPrevious = $iMin
        EndIf
    WEnd

    Local $iPercent = 0
    Local $sKeyValue = '', $sSubKey = ''
    ; Process registry
    While 1
        If Mod($iIndexReg, 10) = 0 Then
            $iPercent = Int($iIndexReg * 100 / $iCurrent)
            ProgressSet($iPercent, $iIndexReg & " keys of " & $iCurrent & " processed (" & $iPercent & "%)")
        EndIf
        $sSubKey = RegEnumKey($sKey, $iIndexReg)
        If @error Then ExitLoop

        $sKeyValue = RegRead($sKey & "\" & $sSubKey, "REG_SZ")
        If @error = 0 Then
            $aResult[$iIndexResult][0] = $sKey & "\" & $sSubKey
            $aResult[$iIndexResult][1] = RegRead($sKey & "\" & $sSubKey, "")
            $iIndexResult += 1
        EndIf

        $iIndexReg += 1
    WEnd

    ProgressOff()
    ReDim $aResult[$iIndexResult][3]

    Return SetError("", "", $aResult)
EndFunc

 

Edited by Jewtus
Link to comment
Share on other sites

; List of the ODBC Drivers installed on this computer
Local $HKEY_LOCAL_MACHINE = 0x80000002
Local $strComputer = "."
Local $objRegistry = ObjGet("winmgmts:\\" & $strComputer & "\root\default:StdRegProv")
Local $strKeyPath = "SOFTWARE\ODBC\ODBCINST.INI\ODBC Drivers"
Local $arrValueNames, $arrValueTypes, $strValue
$objRegistry.EnumValues($HKEY_LOCAL_MACHINE, $strKeyPath, $arrValueNames, $arrValueTypes)
For $i = 0 to UBound($arrValueNames) - 1
    $strValueName = $arrValueNames[$i]
    $objRegistry.GetStringValue($HKEY_LOCAL_MACHINE,$strKeyPath,$strValueName,$strValue)
    ConsoleWrite($arrValueNames[$i] & " -- " & $strValue & @CRLF)
Next
Exit

;)

Link to comment
Share on other sites

13 hours ago, Jewtus said:

How is it that you always have the droids I'm looking for?

By accident ;)

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

10 hours ago, mLipok said:

@water you forgot about ado.au3 ?

No, I didn't :)
But I noticed that the user was asking for ODBC drivers not OLE providers. So I remained silent ;)

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

10 hours ago, PACaleala said:
; List of the ODBC Drivers installed on this computer
Local $HKEY_LOCAL_MACHINE = 0x80000002
Local $strComputer = "."
Local $objRegistry = ObjGet("winmgmts:\\" & $strComputer & "\root\default:StdRegProv")
Local $strKeyPath = "SOFTWARE\ODBC\ODBCINST.INI\ODBC Drivers"
Local $arrValueNames, $arrValueTypes, $strValue
$objRegistry.EnumValues($HKEY_LOCAL_MACHINE, $strKeyPath, $arrValueNames, $arrValueTypes)
For $i = 0 to UBound($arrValueNames) - 1
    $strValueName = $arrValueNames[$i]
    $objRegistry.GetStringValue($HKEY_LOCAL_MACHINE,$strKeyPath,$strValueName,$strValue)
    ConsoleWrite($arrValueNames[$i] & " -- " & $strValue & @CRLF)
Next
Exit

;)

That'll do

Thanks everyone. I'll post the full script in a few.

Link to comment
Share on other sites

For anyone interested:

Pass it a host name and get an array back. Crude but functional.

Func GetMachineInstalls($strComputer="localhost")
    local $aReturn[0][2],$colItems
    $wbemFlagReturnImmediately = 0x10
    $wbemFlagForwardOnly = 0x20
    $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2")
    $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_Product", "WQL", _
                                              $wbemFlagReturnImmediately + $wbemFlagForwardOnly)

    If IsObj($colItems) then
       For $objItem In $colItems
          $sName = $objItem.Name
          $sVersion = $objItem.Version
          _ArrayAdd($aReturn,$sName&"|"&$sVersion,0)
       Next
       Return $aReturn
    Else
       return -1
    Endif
EndFunc

Func GetMachineODBC($strComputer="localhost")
    $HKEY_LOCAL_MACHINE = 0x80000002
    $objRegistry = ObjGet("winmgmts:\\" & $strComputer & "\root\default:StdRegProv")
    $strKeyPath = "SOFTWARE\ODBC\ODBCINST.INI\ODBC Drivers"
    Local $arrValueNames, $arrValueTypes, $strValue, $aReturn[0][2]
    $objRegistry.EnumValues($HKEY_LOCAL_MACHINE, $strKeyPath, $arrValueNames, $arrValueTypes)
    For $i = 0 to UBound($arrValueNames) - 1
        $strValueName = $arrValueNames[$i]
        $objRegistry.GetStringValue($HKEY_LOCAL_MACHINE,$strKeyPath,$strValueName,$strValue)
        _ArrayAdd($aReturn,$arrValueNames[$i]&"|"&$strValue)
    Next
    If UBound($aReturn)>0 then
        Return $aReturn
    Else
        Return -1
    EndIf
EndFunc   

Func GetMachineOS($strComputer="localhost")
    local $aReturn[0][5],$colItems
    $wbemFlagReturnImmediately = 0x10
    $wbemFlagForwardOnly = 0x20
    $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2")
    $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_OperatingSystem", "WQL", _
                                              $wbemFlagReturnImmediately + $wbemFlagForwardOnly)

    If IsObj($colItems) then
       For $objItem In $colItems
          $sArch = $objItem.OSArchitecture
          $sName = $objItem.Caption
          $sVersion = $objItem.Version
          $sBuild = $objItem.BuildNumber
          $sSKU = $objItem.OperatingSystemSKU
          _ArrayAdd($aReturn,$sArch&"|"&$sName&"|"&$sVersion&"|"&$sBuild&"|"&$sSKU,0)
       Next
       Return $aReturn
    Else
       return -1
    Endif
EndFunc

 

Edited by Jewtus
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...