Relevance for checking version part in Registry key name

Hi!

I need a Relevance statement that checks the version part of a Registry subkey’s name under this Registry key:

HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Local Settings\Software\Microsoft\Windows\CurrentVersion\AppModel\PackageRepository\Packages

Here is an example of a Registry subkey name:
MSTeams_24060.2623.2790.8046_x64__8wekyb3d8bbwe

I believe the Relevance I need must be something like this, but I’m struggling:

exists key whose ((preceding texts of firsts "_" of following texts of firsts "MSTeams_" of name of it) = "24060.2623.2790.8046" as version) of key "HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Local Settings\Software\Microsoft\Windows\CurrentVersion\AppModel\PackageRepository\Packages" of registry

Please help!

Thanks!

Arne

Looks like the underscores were lost in my Relevance. There should be one between the two adjacent double quotes and one following the MSTeams string.

Yes there’s a code formatting tag to use in the Forum. Check the icons above the editor window, or the video linked from How to post code to the forums without it messing up the appearance

We can actually take advantage that the ‘as version’ cast tries real hard to find a version in the string we give it:

q: "MSTeams_24060.2623.2790.8046_x64__8wekyb3d8bbwe" as version
A: 24060.2623.2790.8046

so you could probably do something like

q: exists keys whose (name of it starts with "MSTeams_" and name of it as version = version "24060.2623.2790.8046") of key "HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Local Settings\Software\Microsoft\Windows\CurrentVersion\AppModel\PackageRepository\Packages" of native registry

Note that in addition to the ‘as version’ cast, I also switched to using ‘native registry’ because I expect this to show up in a 64-bit registry path.

Wow, great, that is just like other Relevance statements I have used in order to check the Uninstall key!
I was initially thinking ‘as version’ might be that clever, but I never tested it. Thought it might be best to pick the parts of the key name I wanted to check.
Can you please also show how this would be done along the lines of my attempt?
You never know, might come in handy one day! :slight_smile:

And yes, native Registry is where I want to check.

Thanks Jason!

Sure, I can follow along the path where you started - splitting the registry key name on underscores and finding the middle section of it.

First it’s handy to understand the original error coming from the fixlet debugger:

q: exists keys whose ((preceding texts of firsts "_" of following texts of firsts "MSTeams_" of name of it) = "24060.2623.2790.8046" as version) of key "HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Local Settings\Software\Microsoft\Windows\CurrentVersion\AppModel\PackageRepository\Packages" of registry
E: A singular expression is required.

What’s happening here is that inside the whose() clause, we have a plural preceding texts of firsts "_" of following texts of firsts "MSTeams_" of name of it, that is being compared to to the version string.
Because these are defined with plurals following text**s** and first**s**, this is like comparing (1;2) = 1. We can’t compare a plural value to a singular with an equals operator, because some of the comparisons might be true and some of them might be false.

Just to build the query a piece at a time, I’d start by finding the right key name:

q: names whose (it starts with "MSTeams_") of keys of key "HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Local Settings\Software\Microsoft\Windows\CurrentVersion\AppModel\PackageRepository\Packages" of native registry
A: MSTeams_24060.2623.2790.8046_x64__8wekyb3d8bbwe

Then I’d check my logic for splitting that to find the version number:

q: preceding text of first "_" of following text of first "MSTeams_" of names whose (it starts with "MSTeams") of keys of key "HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Local Settings\Software\Microsoft\Windows\CurrentVersion\AppModel\PackageRepository\Packages" of native registry
A: 24060.2623.2790.8046

Finally I’d add on my comparison, moving my string-split logic and value comparison into a whose() clause:

q: exists keys whose ((preceding text of first "_" of following text of first "MSTeams_" of name of it) = "24060.2623.2790.8046" as version) of key "HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Local Settings\Software\Microsoft\Windows\CurrentVersion\AppModel\PackageRepository\Packages" of native registry
A: True

As an alternative, you might ask 'In General, how can plurals be compared? Usually, we can change the equals operator into an 'exists (thing) whose (it compare-operator value), like

q: exists keys whose (exists (preceding texts of firsts "_" of following texts of firsts "MSTeams_" of name of it) whose (it = "24060.2623.2790.8046" as version)) of key "HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Local Settings\Software\Microsoft\Windows\CurrentVersion\AppModel\PackageRepository\Packages" of registry
A: True

You can of course change ‘exists’ to ‘not exists’ to mean “none of these match”; and for advanced forms you could use ‘conjunction of’ to mean “all of these match” or ‘disjunction of’ to mean ‘at least one of these match’. Conjunction and disjunction are used much less frequently than ‘exists’ though.

2 Likes

Thank you Jason for taking the time to enlighten me, excellent!

Best regards,
Arne