Populate list of local DSN's

Deploying to Windows? Utilizing VB Script execution? This is the place to ask Windows-specific questions.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
jfwhite
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 20
Joined: Tue May 10, 2011 9:12 am

Populate list of local DSN's

Post by jfwhite » Wed May 16, 2012 9:22 pm

I need to be able to populate a dropdown list with the names of all local DSN's. This is contained within the registry key:

HKEY_LOCAL_MACHINE/SOFTWARE/ODBC/ODBC.INI/ODBC Data Sources

Now what? :roll:

sturgis
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1685
Joined: Sat Feb 28, 2009 11:49 pm

Re: Populate list of local DSN's

Post by sturgis » Wed May 16, 2012 9:58 pm

You could try
get the queryregistry "HKEY_LOCAL_MACHINE\SOFTWARE\ODBC\ODBC.INI\ODBC Data Sources"
If the key doesn't exist "the result" will contain "no key"

I don't have any odbc stuff set up so don't have a way to check this here but it should get you close.

EDIT: Changed to use backslashes.

jfwhite
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 20
Joined: Tue May 10, 2011 9:12 am

Re: Populate list of local DSN's

Post by jfwhite » Thu May 17, 2012 5:24 pm

Thank you - that is good to know and it works to pull the value of a specific key.

But I described the requirement poorly. What I really need is the listing of key names. For instance, when I click on ODBC\ODBC.ini\ODBC Data Sources in the registry tree, the right pane displays the listing of DSN names. In my case the value of each is SQL Server, and I can retrieve that value by using your suggested approach, but I don't really need the key value, just the name. I would want to populate a list with multiple values such as:

DW1
Lawson_Prod
Kronos_Test

So I'm not sure how to touch those values, and now it seems like I would need some kind of loop to bring them all back.

Thanks again - relative LC newbie here, but my project is coming along nicely except for the DSN issue.

mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3581
Joined: Mon Jan 22, 2007 7:36 am
Contact:

Re: Populate list of local DSN's

Post by mwieder » Thu May 17, 2012 6:23 pm

Try listregistry("HKEY_LOCAL_MACHINE\SOFTWARE\ODBC\ODBC.INI\ODBC Data Sources")

I'm not at a Windows computer at the moment, but it has a chance of working. The ListRegistry function was introduced as an experimental feature in LC 4.5. It's still listed as "experimental", so there are no guarantees.

sturgis
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1685
Joined: Sat Feb 28, 2009 11:49 pm

Re: Populate list of local DSN's

Post by sturgis » Thu May 17, 2012 6:52 pm

If Marks idea doesn't work you could use shell instead.

The following code will grab a whole branch of the registry and put it into the msg box (only tested on win 7) Since I don't have any odbc datasources my example just grabs anything below ODBCINST.INI (rather than ODBC.INI so that I actually get results back)

Once you get the path pointed to the right place you should be able to parse the returned info for what you need.

Code: Select all

put "REG QUERY" && quote & "HKLM\SOFTWARE\ODBC\ODBCINST.INI" & quote && "/s" into tShell
put shell(tShell)
mwieder wrote:Try listregistry("HKEY_LOCAL_MACHINE\SOFTWARE\ODBC\ODBC.INI\ODBC Data Sources")

I'm not at a Windows computer at the moment, but it has a chance of working. The ListRegistry function was introduced as an experimental feature in LC 4.5. It's still listed as "experimental", so there are no guarantees.

mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3581
Joined: Mon Jan 22, 2007 7:36 am
Contact:

Re: Populate list of local DSN's

Post by mwieder » Thu May 17, 2012 7:10 pm

!!! Thanks - I didn't know about that option to regedit. I've got several places where I can put that to use.

jfwhite
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 20
Joined: Tue May 10, 2011 9:12 am

Re: Populate list of local DSN's

Post by jfwhite » Thu May 17, 2012 9:31 pm

I couldn't get Mark's code to return the data I need (although it did work fine for other registry keys), but the shell approach worked fine. Now I have several entries like:

HKEY_LOCAL_MACHINE\SOFTWARE\ODBC\ODBC.INI\OSUMC_BI
Driver REG_SZ C:\Windows\system32\SQLSRV32.dll
Server REG_SZ osumc-boedgeds
Database REG_SZ OSUMC_BI
LastUser REG_SZ jwhite
Trusted_Connection REG_SZ Yes


So it will be good practice for me to figure out how to parse out the DSN name only. Many thanks to you both.

shaosean
Posts: 906
Joined: Thu Nov 04, 2010 7:53 am

Re: Populate list of local DSN's

Post by shaosean » Thu May 17, 2012 11:05 pm

Look at the entries for lineOffest and itemDelimiter.

Post Reply