-1

(My ultimate goal is to verify if a specific database OCDB driver is installed before I run an Autolisp coded connection to a database)

I would like to know : How can i check if a driver is installed on a Windows 10 x64 computer, using AutoLISP on BricsCAD (or else AutoCAD)?

Also, may i have your commentaraies on the possibility of programatically installing the driver using autolisp? I guess, there are some wrappers available or in the worst case, i can simply launch the manual installation using (startapp "Explorer" "...installer-winx64.msi").

Thanks,

Lee Mac
  • 15,615
  • 6
  • 32
  • 80

2 Answers2

0

To ascertain whether the driver is installed, you could interrogate the Win32_SystemDriver WMI class - consider the following example:

;; Win32 System Driver-p  -  Lee Mac
;; Returns T if a driver exists with the supplied name

(defun LM:win32systemdriver-p ( drv )
    (LM:wmiqueryhasmembers-p (strcat "select * from win32_systemdriver where name = '" drv "'"))
)

;; WMI Query has Members-p  -  Lee Mac
;; Returns T if the supplied WMI query has members

(defun LM:wmiqueryhasmembers-p ( qry / rtn srv wmi )
    (if (setq wmi (vlax-create-object "wbemscripting.swbemlocator"))
        (progn
            (setq rtn
                (vl-catch-all-apply
                   '(lambda ( )
                        (setq srv (vlax-invoke wmi 'connectserver)
                              qry (vlax-invoke srv 'execquery qry)
                        )
                        (< 0 (vla-get-count qry))
                    )
                )
            )
            (foreach obj (list qry srv wmi)
                (if (= 'vla-object (type obj)) (vlax-release-object obj))
            )
            (and (not (vl-catch-all-error-p rtn)) rtn)
        )
    )
)
Lee Mac
  • 15,615
  • 6
  • 32
  • 80
  • I replaced the "=" in your query with a "like" in order to use the % wildcard and tested your code and i think i can only find drivers within the directory "C:\WINDOWS\System32\DRIVERS\" ... I think these guys found the answer : https://devblogs.microsoft.com/scripting/how-can-i-get-a-list-of-the-odbc-drivers-that-are-installed-on-a-computer/ but again, I wouldn't know how to search and check registry keys using Autolisp. Also, how could i find the right registry key for the specific ODBC driver i'm concerned with? – 1LandSurveyor Sep 07 '22 at 22:06
  • Again, according to this : https://www.oreilly.com/library/view/adonet-cookbook/0596004397/ch10s17.html, i simply need to query the registry key HKEY_LOCAL_MACHINE\SOFTWARE\ODBC\ODBCINST.INI\ODBC Drivers, which contains a list of the ODBC driver names and perform a WCMATCH on it to check if mine is there. – 1LandSurveyor Sep 07 '22 at 22:17
  • Check the vl-registry-read function. – Lee Mac Sep 07 '22 at 22:24
  • I did... Had no successful result using `(vl-registry-read "HKEY_LOCAL_MACHINE\\SOFTWARE\\ODBC\\ODBCINST.INI" "ODBC Drivers")` EDIT: but I managed to find a specific working key : `(vl-registry-read "HKEY_LOCAL_MACHINE\\SOFTWARE\\ODBC\\ODBCINST.INI\\MySQL ODBC 3.51 Driver" "Driver")` which i guess accomplishes what i want. I will test the variable with different PCs and see the result. Thanks a lot! – 1LandSurveyor Sep 07 '22 at 22:45
0

The adopted test is simply : (member "MySQL ODBC 3.51 Driver" ; Driver name in the Windows Registry (vl-registry-descendents "HKEY_LOCAL_MACHINE\\SOFTWARE\\ODBC\\ODBCINST.INI\\"))

Which will reliably give the right answer for the driver if ran either on a x86 process (32 bit app) or a x64 process using a x64 system.