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

    Retrieve System and User DSN in ODBC

    johnk Apprentice

      Hi,

       

      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?

       

      Thanks

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

          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.

           

          Thanks

          Brandon

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

            Thanks

            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.Close
            'objFile = objFSO.OpenTextFile(outFile, ForAppending, True)

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

            if myStringMachine <> "" Then
            objFile.WriteLine "Machine DSN:" & myStringMachine
            'WshShell.RegWrite ODBCKeyMachineDSN,myStringMachine,"REG_SZ"
            Else
            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 
              Else
               myStringUser = subkey
              End If
            End If
            Next

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

            'WScript.Echo "Finished"

            ---------------------------------------------------------------------------------