Getting certain registry keys and values of subsequent strings

(imported topic written by JesseR91)

I got an interesting one. I want to retrieve the DSN information from our servers and I created the following relevance that gets the names of the DSN connections and what type they are.

(((name of it & " = " & it as string)of values of it)) of key “HKEY_LOCAL_MACHINE\SOFTWARE\ODBC\ODBC.INI\ODBC Data Sources” of registry

Now, I need to be able to get the actual details of each DSN. Under the registry key HKEY_LOCAL_MACHINE\SOFTWARE\ODBC\ODBC.INI\ it has each DSN listed as a key with the details that I need as values. The problem is, there are 2 keys in this thread that are NOT DSN’s. One is the ODBC Data Sources Key and the other is ODBC File DSN. How would I be able to get the values of the DSN’s from the name of the keys I retrieved from my relevance and NOT anything else?

(imported comment written by jessewk)

This will give you the name of each of the keys under ODBC.INI followed by the concatenation of its values, except the two ODBC keys:

(name of it & " = " & (concatenation "; " of (it as string) of values of it)) of keys whose (name of it != “ODBC Data Sources” AND name of it != “ODBC File DSN”) of key “HKEY_LOCAL_MACHINE\SOFTWARE\ODBC\ODBC.INI” of registry

Example results:

bes_bfenterprise = C:\WINDOWS\system32\sqlsrv32.dll; (local); BFEnterprise; SYSTEM; Yes
bes_EnterpriseServer = C:\WINDOWS\system32\sqlsrv32.dll; SYSTEM; BFEnterprise; (local)

You can add more logic to get only specific values or to list the results differently. If you’re having trouble, post an example of the output format you’d prefer.

-Jesse

(imported comment written by JesseR91)

!! Thanks Jesse. I forgot about the ‘!=’ statement. Thank You.

(imported comment written by JesseR91)

Would it be possible to have the format as:

DSN Name = bes_bfenterprise ; Value Name = Value Result ?

Each key has dword names so could you have the dword names + their value?

For instance, under bes_bfenterprise there are 4 dword values named ‘Database’, ‘Driver’, ‘LastUser’, ‘Server’ and each has a value of it. Can they be listed out as such?

(imported comment written by jessewk)

How about this:

(name of it & ": " & (concatenation "; " of (name of it & “=” & it as string) of values of it)) of keys whose (name of it != “ODBC Data Sources” AND name of it != “ODBC File DSN”) of key “HKEY_LOCAL_MACHINE\SOFTWARE\ODBC\ODBC.INI” of registry

Example output:

bes_bfenterprise: Driver=C:\WINDOWS\system32\sqlsrv32.dll; Server=(local); Database=BFEnterprise; LastUser=SYSTEM; Trusted_Connection=Yes
bes_EnterpriseServer: Driver=C:\WINDOWS\system32\sqlsrv32.dll; LastUser=SYSTEM; Database=BFEnterprise; Server=(local)

(imported comment written by JesseR91)

You da man

(imported comment written by JesseR91)

Jesse,

To pull just the name & ‘server’ value would that be a whose statement on the value?

(imported comment written by JesseR91)

What looks wrong with this?

(“DSN=” & name of it & ": " & (concatenation "; " of (name of it & “=” & it as string ) of values whose (name of it = “Server”) of it)) of keys whose (name of it != “ODBC Data Sources” AND name of it != “ODBC File DSN”) of key “HKEY_LOCAL_MACHINE\SOFTWARE\ODBC\ODBC.INI” of registry

ugh!

(imported comment written by jessewk)

Your relevance works for me. What behavior are seeing as incorrect?

Here’s an example output from your query on my box:

DSN=bes_besinternal: Server=besinternal.bigfix.com
DSN=bes_bfenterprise: Server=(local)
DSN=bes_EnterpriseServer: Server=(local)

(imported comment written by JesseR91)

Oh, I guess I did do it right. There are a couple DSN’s on my box that don’t have a ‘Server’ key so it was showing nothing.

Is there a way if there is no Server value to not report the dsn?

My output

DSN=aridb:

DSN=bes_bfenterprise: Server=161.89.145.217

DSN=Xtreme Sample Database 2003:

DSN=Xtreme Sample Database 2005:

Basically the 3 DSN’s with no Server value, I want to not show up. I assume it would be a IF/Then?

(imported comment written by jessewk)

You just need to add an extra whose clause:

(“DSN=” & name of it & ": " & (concatenation "; " of (name of it & “=” & it as string ) of values whose (name of it = “Server”) of it)) of keys whose (name of it != “ODBC Data Sources” AND name of it != “ODBC File DSN” AND exists value whose (name of it = “Server”) of it) of key “HKEY_LOCAL_MACHINE\SOFTWARE\ODBC\ODBC.INI” of registry