2 Replies Latest reply on Jul 28, 2015 5:11 PM by johnk

    Retrieve System and User DSN in ODBC




      I had a look around in Landesk to see if it's possible to retrieve a list of System and User DSNs from the registry. I have looked at custom data -- registry items but what we would be looking for is subkeys within HKLM\SOFTWARE\ODBC\ODBC.INI\ODBC Data Sources, these subkeys are unkown since users can call them whatever they want however the custom data requires a known key to retrieve custom data.


      Has anyone performed this within Landesk? if so how?



        • 1. Re: Retrieve System and User DSN in ODBC

          Hi, the inventory product doesnt traverse hives for unknown subkeys in its current design. There is an exception where it will gather everything from the HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Intel\LANDesk\Inventory\Custom Fields key.

          So your best options are to put together a custom script or program that writes the data to your custom data, or copy those keys into the custom fields hive.




          1 of 1 people found this helpful
          • 2. Re: Retrieve System and User DSN in ODBC


            What I ended up doing was creating the following vbs script... and just created a file for each username with the DSNs that were not in the default list. It is only temporary and this did the trick but I guess you can edit this script to create the registry entries instead.


            'List Registry Subkeys
            'On Error Resume Next
            ODBCKeyMachineDSN = "HKCU\Software\ODBC\MachineDSN"
            ODBCKeyUserDSN = "HKCU\Software\ODBC\UserDSN"

            Const HKEY_LOCAL_MACHINE = &H80000002
            Const HKEY_CURRENT_USER = &H80000001
            Set WshShell = CreateObject("WScript.Shell")
            Dim myStringMachine
            Dim myStringUser
            Dim outFile
            Dim objFSO
            Dim objFile
            strComputer = "."
            strUser = CreateObject("WScript.Network").UserName

            Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _
                strComputer & "\root\default:StdRegProv")

            strKeyPath = "SOFTWARE\ODBC\ODBC.INI"
            oReg.EnumKey HKEY_LOCAL_MACHINE, strKeyPath, arrSubKeys

            outFile="\\<serverlocation>\<share>\Communal Documents\" & strUser & ".txt"
            'WScript.Echo outFile
            Set objFSO=CreateObject("Scripting.FileSystemObject")
            set objFile = objFSO.CreateTextFile(outFile,True)
            'objFile = objFSO.OpenTextFile(outFile, ForAppending, True)

            For Each subkey In arrSubKeys
                If subkey <> "ODBC Data Sources" Then
              If myStringMachine <> "" Then
               myStringMachine = myStringMachine & "," & subkey 
               myStringMachine = subkey
              End If
            End If

            if myStringMachine <> "" Then
            objFile.WriteLine "Machine DSN:" & myStringMachine
            'WshShell.RegWrite ODBCKeyMachineDSN,myStringMachine,"REG_SZ"
            objFile.WriteLine "Machine DSN:" & "No DSN Entries"
            'WshShell.RegWrite ODBCKeyMachineDSN,"No DSN Entries","REG_SZ"
            End If

            oReg.EnumKey HKEY_CURRENT_USER, strKeyPath, arrSubKeys
            For Each subkey In arrSubKeys

                If subkey <> "ODBC Data Sources" AND subkey <> "dBASE Files" AND subkey <> "Excel Files" AND subkey <> "MS Access Database" AND subkey <> "ODBC" Then
              If myStringUser <> "" Then
               myStringUser = myStringUser & "," & subkey 
               myStringUser = subkey
              End If
            End If

            if myStringUser <> "" Then
            objFile.WriteLine "User DSN:" & myStringUser
            'WshShell.RegWrite ODBCKeyUserDSN,myStringUser,"REG_SZ"
            objFile.WriteLine "User DSN:" & "No DSN Entries"
            'WshShell.RegWrite ODBCKeyUserDSN,"No DSN Entries","REG_SZ"
            End If
            Set WshShell = Nothing

            'WScript.Echo "Finished"