This one turned out to be a bit tricky. I’ve had cases where we need to retrieve the “highest version among registry keys” and “all but the highest version”, but not a need to retrieve all but the top 2 versions.
If we have a set of strings, we can build a set that excludes the highest value (after casting to a version):
q: ((maxima of (elements of it as version) as string) ) of set of ("19.3.510";"20.4.1116";"20.2.25203";"18.3.419")
A: 20.4.1116
T: 0.090 ms
I: plural string
And we can remove that one maxima value from the set through a set subtraction:
q: (elements of (it - set of (maxima of (elements of it as version) as string) )) of set of ("19.3.510";"20.4.1116";"20.2.25203";"18.3.419")
A: 18.3.419
A: 19.3.510
A: 20.2.25203
T: 0.117 ms
I: plural string
We can repeat that to remove the top two elements from the set:
q: elements of (it - set of (maxima of (elements of it as version) as string) ) of (it - set of (maxima of (elements of it as version) as string) ) of set of ("19.3.510";"20.4.1116";"20.2.25203";"18.3.419")
A: 18.3.419
A: 19.3.510
T: 0.141 ms
I: plural string
I built a set of fake registry keys on my machine to retrieve these values from the Registry.
q: ((value "DisplayVersion" of it as string, Name of it as string) of keys whose ((value "DisplayName" of it as string as lowercase starts with "Tableau" as lowercase) AND (value "UninstallString" of it as string as lowercase contains "msiexec")) of keys "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall" of (x32 registries; x64 registries))
A: 19.3.510, tableau1
A: 20.4.1116, tableau2
A: 20.2.25203, tableau3
A: 18.3.419, tableau4
T: 8.207 ms
I: plural ( string, string )
I’m indenting this relevant for a little bit more readability. Here I add the maxima and set subtraction logic to get the registry keys for all but the highest two versions:
items 1 of (
it
, keys whose (
value "DisplayName" of it as string as lowercase starts with "Tableau" as lowercase
AND value "UninstallString" of it as string as lowercase contains "msiexec"
) of keys "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall" of (x32 registries; x64 registries)
) whose (value "DisplayVersion" of item 1 of it as string is contained by item 0 of it) of (
it - set of (maxima of (elements of it as version) as string)
) of (
it - set of (maxima of (elements of it as version) as string)
) of
set of (values "DisplayVersion" of it as string) of keys whose (
value "DisplayName" of it as string as lowercase starts with "Tableau" as lowercase
AND value "UninstallString" of it as string as lowercase contains "msiexec"
) of keys "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall" of (x32 registries; x64 registries)
A: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\tableau1
A: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\tableau4