Concatenation fails after retrieving value

I am trying to get the string value of this registry path, so I can get a key value from it, but the third part of the concatenation “\MSSQLServer\CurrentVersion” fails to be appended to the string I am constructing. Any suggestion as to why?

this is the code snippet I am evaluating

("SOFTWARE\Microsoft\Microsoft SQL Server\" & (value "InstalledInstances" of key "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server" of native registry as string) & "\MSSQLServer\CurrentVersion") as string

i had orignally posted the following code snippet in my original post, which was not what i meant to refer to. this snippet actually tries to get the value but comes back as undefined as the path to the registry key is not correctly being built

value "CurrentVersion" of key ("SOFTWARE\Microsoft\Microsoft SQL Server\" & (value "InstalledInstances" of key "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server" of native registry as string) & "\MSSQLServer\CurrentVersion") of native registry

Welcome to the BigFix Community!

I’d start by breaking this into simpler statements and checking whether the results are what you expect.

Try these in the Fixlet Debugger or in the WebUI Query app:

q: (value "InstalledInstances" of key "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server" of native registry as string)

– is InstalledInstances retrieved? Is there exactly one, or is there more than one?

q: (value "InstalledInstances" of key "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server" of native registry as string) & "\MSSQLServer\CurrentVersion"

– Does this give you a result? Is it what you expected?

q: key ("SOFTWARE\Microsoft\Microsoft SQL Server" & (value "InstalledInstances" of key "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server" of native registry as string) & "\MSSQLServer\CurrentVersion") of native registry

– Does that give a result? I expect it won’t - the leftmost registry path should start with “HKEY_LOCAL_MACHINE”. Fix that and see whether you get a result then?

2 Likes

I am sorry I am not a developer, so I am a bit out of my element, and I am having difficulty expressing the issue.

I agree that the string should be prefixed by “HKEY_LOCAL_MACHINE” however I am not yet trying to retrieve the actual key value, but to make sure my string representing the path is constructed the way i think it should be.

For right now, I was trying to get the analysis to return the string only (and not the value) as a troubleshooting step. What is happening, is that the full concatenation is not happening.

In my example, I know that:

value “InstalledInstances” of key “HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server”

returns VEEAMSQL2016 as expected

However the result of the expression is missing the suffix, after the second concatenation:

SOFTWARE\Microsoft\Microsoft SQL Server\VEEAMSQL2016

The string “\MSSQLServer\CurrentVersion” is not appended as I would have expected from my expression. Could bigfix be returning some kind of terminating character when it retrieved the value of the rgistry key in the middle of the concatenation? If I try a bogus expression such as:

“alpha” & “bravo” & “charlie”

I get the expected result, but it is as if “charlie” is not printed.

I apologize. the first example I cited was the attempt to retrieve the key value.

I had originally quoted the wrong code snippet in my original post, I apologize and will edit it if I can. Here is what I am actually trying to evaluate:

("SOFTWARE\Microsoft\Microsoft SQL Server\" & (value "InstalledInstances" of key "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server" of native registry as string) & "\MSSQLServer\CurrentVersion") as string

The content of InstalledInstances contains trailing NUL characters, represented as %00%00 in the output.

If you want to exclude them, you’ll have to perform some substring manipulation like:

Q: (preceding text of first "%00" of  (it as string), type of it) of (value "InstalledInstances" of key "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server" of native registry)
A: MSSQLSERVER, REG_MULTI_SZ
T: 0.361 ms
I: singular ( substring, registry key value type ) 

The type of this registry key value is multi-string, so each line of the content is separated by the pair of null characters.

Pulling this together, you would get the following:

Q: ("SOFTWARE\Microsoft\Microsoft SQL Server\" & preceding text of first "%00" of(value "InstalledInstances" of key "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server" of native registry as string) & "\MSSQLServer\CurrentVersion") as string
A: SOFTWARE\Microsoft\Microsoft SQL Server\MSSQLSERVER\MSSQLServer\CurrentVersion
T: 0.160 ms
I: singular string
1 Like

Ah! This makes sense, I was wondering if somehow a non-printable character was causing the issue with concatenation. I did not know that those registry values were padded with null characters.

I got the query working now, and it gives results as expected, for SQL server versions that are installed in non-standard instances only I guess.

value "CurrentVersion" of key ("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server\" & preceding text of first "%00" of (value "InstalledInstances" of key "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server" of native registry as string) & "\MSSQLServer\CurrentVersion") of native registry

apparently if the instance has the default name of MSSQLSERVER then the CurrentVersion string is stored in a key like MSSQL12.MSSQLSERVER or MSSQL16.MSSQLSERVER depending on version. Why is it so complicated? LOL. Oh well. But that is another issue.

Anyhow, thank you for your help with this! :slight_smile:

Glad this helped you out.