Registry key with multiple values

Hi All,

This should be a simple enough relevance check, but I dug myself into a rabbit hole and I just cannot get it :frowning:

Here is the relevance:

value “SQLPath” of key (“HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server” & (value of key “HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server\Instance Names\SQL” of native registry) as string & “\Setup”) of native registry

Basically, I have some systems with multiple MS SQL instances and I am trying to return the values of the SQL path for each instance. This is working fine for systems with one instance, but then I get the “Singular expression refers to non-unique object” for systems with multiple.

q: values “SQLPath” of key (“HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server” & (value of key “HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server\Instance Names\SQL” of native registry) as string & “\Setup”) of native registry
A: c:\Program Files\Microsoft SQL Server\MSSQL11.SQLEXPRESS\MSSQL
E: Singular expression refers to non-unique object.

q: (values of key “HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server\Instance Names\SQL” of native registry) as string
A: MSSQL11.SQLEXPRESS
A: MSSQL11.INSTANCE1

Thanks

Martin

Have you tried pluralising key to keys ?

I think you mean “keys of key”.

values of keys of key "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server" of native registry

I’m just running this on a workstation of mine that has some SQL elements on it and running it gave me this:

Q: values of keys of key "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server" of native registry
A: c:\Program Files\Microsoft SQL Server\100\Shared\ErrorDumps\
A: 
A: 240
A: c:\Program Files\Microsoft SQL Server\100\Shared\
A: c:\Program Files\Microsoft SQL Server\100\
A: c:\Program Files\Microsoft SQL Server\90\Shared\
A: c:\Program Files\Microsoft SQL Server\90\
T: 0.374 ms
I: plural registry key value
F: Fingerprintable: true, Path: 0x00000001, Path Sum: 0x04c81bd4, Bits: 0x80000000, Global Sum: 0x04c82547, Seems Unchanged: true

Yep, tried that also.

q: values “SQLPath” of keys (“HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server” & (value of keys “HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server\Instance Names\SQL” of native registry) as string & “\Setup”) of native registry
A: c:\Program Files\Microsoft SQL Server\MSSQL11.SQLEXPRESS\MSSQL
E: Singular expression refers to non-unique object.

//value to values
q: values “SQLPath” of keys (“HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server” & (values of keys “HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server\Instance Names\SQL” of native registry) as string & “\Setup”) of native registry
E: A singular expression is required.

Hi jmaple,

I am trying to determine where the instance is running from. Some systems it is C:… some are on other drives.

So I need to determine all the instances that are defined, so the following does provide that:

(values of key “HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server\Instance Names\SQL” of native registry) as string

I then try to use the returns from the above to piece together the query for registry path. It works perfectly when there is only one instance, but I get the error when there are multiple instances. I need to use the first query as there is no standard to the instance names.

Thanks for the help.

The concatenate “&” requires singular expression, so you can’t feed it the plurals directly. Try something like

q: values "SQLPath" of keys (("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server\" & it  & "\Setup") of ((values of keys "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server\Instance Names\SQL" of native registry) as string)) of native registry
1 Like