Maximum of (sub key of registry as version)

(imported topic written by lmpymilk91)

What I would like to do is get back “A: 10.9.9.21”.

Also is there a way to get this information on pre 7.1?

Thanks

Chris

q:(names of (keys whose (exists value "MyStringName" whose (it as string as lowercase is "mystingvalue" of it) of it) of key "HKEY_LOCAL_MACHINE\SOFTWARE\MyCompanyKEY\MyApplicationKEY\MyVersionsKEY" of registry) as string as version)
A: 10.1.2.3
A: 10.2.3.4
A: 10.5.6.7
A: 10.8.9.10
A: 10.8.9.16
A: 10.9.9.21

(imported comment written by BenKus)

Hey Chris,

This is tricky because currently the “maximum” operator only works on numbers… You could do some tricks to convert your IPs (or versions?) to a big integer, get the max, then convert it back…

I just worked on this and it turned out to be much harder than I expected, but I think I got it:

(preceding text of position (length of it-18) of it as integer as string & “.” & first 6 of following text of position (length of it-18) of it as integer as string & “.” & first 6 of following text of position (length of it-12) of it as integer as string & “.” & first 6 of following text of position (length of it-6) of it as integer as string) of (it as string) of maximum of (it as integer) of ( last 6 of (“000000” & parenthesized part 1 of it) & last 6 of (“000000” & parenthesized part 2 of it) & last 6 of (“000000” & parenthesized part 3 of it) & last 6 of (“000000” & parenthesized part 4 of it )) of matches (regex “(\d+).(\d+).(\d+).(\d+)”) of (it as string ) of (names of (keys whose (exists value “MyStringName” whose (it as string as lowercase is “mystingvalue” of it) of it) of key “HKEY_LOCAL_MACHINE\SOFTWARE\MyCompanyKEY\MyApplicationKEY\MyVersionsKEY” of registry) as string as version)

Ben

(imported comment written by lmpymilk91)

Good Morning Ben, I took a look at this and it doesn’t seem to be working for me.

I am getting a “Error: Singular expression refers to nonexistent object.”

Here is the registry key information that I’ve been using.

Windows Registry Editor Version 5.00   [HKEY_LOCAL_MACHINE\SOFTWARE\MyCompanyKEY] [HKEY_LOCAL_MACHINE\SOFTWARE\MyCompanyKEY\MyApplicationKEY] [HKEY_LOCAL_MACHINE\SOFTWARE\MyCompanyKEY\MyApplicationKEY\MyVersionsKEY] [HKEY_LOCAL_MACHINE\SOFTWARE\MyCompanyKEY\MyApplicationKEY\MyVersionsKEY\1.2.3.4] 
"MyStringName"=
"mystingvalue" [HKEY_LOCAL_MACHINE\SOFTWARE\MyCompanyKEY\MyApplicationKEY\MyVersionsKEY\5.6.7.8] 
"MyStringName"=
"mystingvalue" [HKEY_LOCAL_MACHINE\SOFTWARE\MyCompanyKEY\MyApplicationKEY\MyVersionsKEY\9.10.11.12] 
"MyStringName"=
"mystingvalue" [HKEY_LOCAL_MACHINE\SOFTWARE\MyCompanyKEY\MyApplicationKEY\MyVersionsKEY\13.14.15.16] 
"MyStringName"=
"mystingvalue"

Now if I use this for my registry I get back the “9.10.11.12” that I would expect.

Windows Registry Editor Version 5.00   [HKEY_LOCAL_MACHINE\SOFTWARE\MyCompanyKEY] [HKEY_LOCAL_MACHINE\SOFTWARE\MyCompanyKEY\MyApplicationKEY] [HKEY_LOCAL_MACHINE\SOFTWARE\MyCompanyKEY\MyApplicationKEY\MyVersionsKEY] [HKEY_LOCAL_MACHINE\SOFTWARE\MyCompanyKEY\MyApplicationKEY\MyVersionsKEY\1.2.3.4] 
"MyStringName"=
"mystingvalue" [HKEY_LOCAL_MACHINE\SOFTWARE\MyCompanyKEY\MyApplicationKEY\MyVersionsKEY\5.6.7.8] 
"MyStringName"=
"mystingvalue" [HKEY_LOCAL_MACHINE\SOFTWARE\MyCompanyKEY\MyApplicationKEY\MyVersionsKEY\9.10.11.12] 
"MyStringName"=
"mystingvalue"

(imported comment written by BenKus)

Ok… I had a regex problem AND a max integer problem… Try this instead:

(preceding text of position (length of it-15) of it as integer as string & “.” & first 5 of following text of position (length of it-15) of it as integer as string & “.” & first 5 of following text of position (length of it-10) of it as integer as string & “.” & first 5 of following text of position (length of it-5) of it as integer as string) of (it as string) of maximum of (it as integer) of ( last 5 of (“00000” & parenthesized part 1 of it) & last 5 of (“000000” & parenthesized part 2 of it) & last 5 of (“00000” & parenthesized part 3 of it) & last 5 of (“00000” & parenthesized part 4 of it )) of matches (regex “^(\d+).(\d+).(\d+).(\d+)$”) of (it as string ) of (names of (keys whose (exists value “MyStringName” whose (it as string as lowercase is “mystingvalue” of it) of it) of key “HKEY_LOCAL_MACHINE\SOFTWARE\BigFix\test” of registry) as string as version)

Note that you can’t have any number with more than 5 digits between the “.” for this to work…

Ben

(imported comment written by Jim23)

Hello Chris,

You might also try:

(preceding text of position (length of it-12) of it as integer as string & “.” & first 4 of following text of position (length of it-12) of it as integer as string & “.” & first 4 of following text of position (length of it-8) of it as integer as string & “.” & first 4 of following text of position (length of it-4) of it as integer as string) of (it as string) of maximum of (it as integer) of (last 4 of (“000000” & parenthesized part 1 of it) & last 4 of (“000000” & parenthesized part 2 of it) & last 4 of (“000000” & parenthesized part 3 of it) & last 4 of (“000000” & parenthesized part 4 of it )) of matches (regex “(\d+).(\d+).(\d+).(\d+)”) of (it as string ) of (names of (keys whose (exists value “MyStringName” whose (it as string as lowercase is “mystingvalue” of it) of it) of key “HKEY_LOCAL_MACHINE\SOFTWARE\MyCompanyKEY\MyApplicationKEY\MyVersionsKEY” of registry) as string as version)

A: 13.14.15.16

This assumes that each value between the “.” will not be longer than 4 digits. For instance:

12345.3.8.5 would be invalid but 1234.3.8.5 would be valid.

Ben,

I’m not sure what the issue is, but the relevance debugger did not like the number:

000013000014000015000016 which is output from the sample data above. Looking at 4 characters instead of 6 seemed to work.

q: “000013000014000015000016” as integer

E: Singular expression refers to nonexistent object.

q: “0013001400150016” as integer

A: 13001400150016

(imported comment written by NoahSalzman)

You can always use floating point instead of integer:

Q: floating point “12345678901234567890e+0”

A: 12345678901234567890

Q: 12345678901234567890 as integer

E: Singular expression refers to nonexistent object.

(imported comment written by lmpymilk91)

Thanks for the help on this, everything is now working great.

(imported comment written by lmpymilk91)

Well it was working great until I found the sub keys (versions) can be like one of the following.

1

1.2

1.2.3

1.2.3.4

(imported comment written by Jim23)

We could also order them using unique values, concatenate it and then grab the last one. Does this work?

following text of last “:==:” of concatenation “:==:” of (it as string) of unique values of (it as version) of (names of (keys whose (exists value “MyStringName” whose (it as string as lowercase is “mystingvalue” of it) of it) of key “HKEY_LOCAL_MACHINE\SOFTWARE\MyCompanyKEY\MyApplicationKEY\MyVersionsKEY” of registry) as string as version)

(imported comment written by lmpymilk91)

Jim,

Here is how I have the registry setup now and hoping to see 16.5

[HKEY_LOCAL_MACHINE\SOFTWARE\MyCompanyKEY\MyApplicationKEY\MyVersionsKEY\1] 
"MyStringName"=
"mystingvalue"   [HKEY_LOCAL_MACHINE\SOFTWARE\MyCompanyKEY\MyApplicationKEY\MyVersionsKEY\1.1] 
"MyStringName"=
"mystingvalue"   [HKEY_LOCAL_MACHINE\SOFTWARE\MyCompanyKEY\MyApplicationKEY\MyVersionsKEY\1.1.1] 
"MyStringName"=
"mystingvalue"   [HKEY_LOCAL_MACHINE\SOFTWARE\MyCompanyKEY\MyApplicationKEY\MyVersionsKEY\1.1.1.1] 
"MyStringName"=
"mystingvalue"   [HKEY_LOCAL_MACHINE\SOFTWARE\MyCompanyKEY\MyApplicationKEY\MyVersionsKEY\15] 
"MyStringName"=
"mystingvalue"   [HKEY_LOCAL_MACHINE\SOFTWARE\MyCompanyKEY\MyApplicationKEY\MyVersionsKEY\15.1] 
"MyStringName"=
"mystingvalue"   [HKEY_LOCAL_MACHINE\SOFTWARE\MyCompanyKEY\MyApplicationKEY\MyVersionsKEY\15.1.1] 
"MyStringName"=
"mystingvalue"   [HKEY_LOCAL_MACHINE\SOFTWARE\MyCompanyKEY\MyApplicationKEY\MyVersionsKEY\15.1.1.1] 
"MyStringName"=
"mystingvalue"   [HKEY_LOCAL_MACHINE\SOFTWARE\MyCompanyKEY\MyApplicationKEY\MyVersionsKEY\16] 
"MyStringName"=
"mystingvalue"   [HKEY_LOCAL_MACHINE\SOFTWARE\MyCompanyKEY\MyApplicationKEY\MyVersionsKEY\16.1] 
"MyStringName"=
"mystingvalue"   [HKEY_LOCAL_MACHINE\SOFTWARE\MyCompanyKEY\MyApplicationKEY\MyVersionsKEY\16.1.1] 
"MyStringName"=
"mystingvalue"   [HKEY_LOCAL_MACHINE\SOFTWARE\MyCompanyKEY\MyApplicationKEY\MyVersionsKEY\16.1.1.1] 
"MyStringName"=
"mystingvalue"   [HKEY_LOCAL_MACHINE\SOFTWARE\MyCompanyKEY\MyApplicationKEY\MyVersionsKEY\16.5] 
"MyStringName"=
"mystingvalue"

using this in qna-7.0.9.164 it returns “E: The operator “unique values” is not defined.”

using this in qna-7.2.1.357 it returns “16”

as it only looks at…

1

15

16

(imported comment written by lmpymilk91)

but this does seem to work, removing the “of unique values”

following text of last “:==:” of concatenation “:==:” of (it as string) of (it as version) of (names of (keys whose (exists value “MyStringName” whose (it as string as lowercase is “mystingvalue” of it) of it) of key “HKEY_LOCAL_MACHINE\SOFTWARE\MyCompanyKEY\MyApplicationKEY\MyVersionsKEY” of registry) as string as version)

I will test a bit more and report back.

(imported comment written by Jim23)

Without unique values it will grab the last one in the order that they are in the registry. With unique values it will put them in order first and then give the last. For instance here is the order I put them in the registry (including an “A” to check for invalid data):

Without “unique values”:

q: (names of (keys whose (exists value “MyStringName” whose (it as string as lowercase is “mystingvalue” of it) of it) of key “HKEY_LOCAL_MACHINE\SOFTWARE\MyCompanyKEY\MyApplicationKEY\MyVersionsKEY” of registry) as string as version)

A: 1.2.3.4

A: 13.14.15.16

A: 15

A: 3.4

A: 5.6.7.8

A: 9.10.11.12

T: 0.254 ms

I: plural version

With “unique values”

q: unique values of (names of (keys whose (exists value “MyStringName” whose (it as string as lowercase is “mystingvalue” of it) of it) of key “HKEY_LOCAL_MACHINE\SOFTWARE\MyCompanyKEY\MyApplicationKEY\MyVersionsKEY” of registry) as string as version)

A: 1.2.3.4

A: 3.4

A: 5.6.7.8

A: 9.10.11.12

A: 13.14.15.16

A: 15

T: 0.280 ms

I: plural version with multiplicity

(imported comment written by Jim23)

OK… I think this one may do. If we pad the version so that all versions have the same amount of blocks then compare using Ben’s code above that should give us the highest version. We will finally then remove the trailing 0’s. Will this work?

//padded response

q: (preceding text of position (length of it-12) of it as integer as string & “.” & first 4 of following text of position (length of it-12) of it as integer as string & “.” & first 4 of following text of position (length of it-8) of it as integer as string & “.” & first 4 of following text of position (length of it-4) of it as integer as string) of (it as string) of maximum of (it as integer) of (last 4 of (“000000” & parenthesized part 1 of it) & last 4 of (“000000” & parenthesized part 2 of it) & last 4 of (“000000” & parenthesized part 3 of it) & last 4 of (“000000” & parenthesized part 4 of it )) of matches (regex “(\d+).(\d+).(\d+).(\d+)”) of ((pad of it as string) of (names of (keys whose (exists value “MyStringName” whose (it as string as lowercase is “mystingvalue” of it) of it) of key “HKEY_LOCAL_MACHINE\SOFTWARE\MyCompanyKEY\MyApplicationKEY\MyVersionsKEY” of registry) as string as version))

A: 13.15.8.0

T: 0.854 ms

I: singular string

//not padded response

q: (if (it contains “.0.” or it ends with “.0”) then (preceding text of first “.0” of it) else (it)) of ((preceding text of position (length of it-12) of it as integer as string & “.” & first 4 of following text of position (length of it-12) of it as integer as string & “.” & first 4 of following text of position (length of it-8) of it as integer as string & “.” & first 4 of following text of position (length of it-4) of it as integer as string) of (it as string) of maximum of (it as integer) of (last 4 of (“000000” & parenthesized part 1 of it) & last 4 of (“000000” & parenthesized part 2 of it) & last 4 of (“000000” & parenthesized part 3 of it) & last 4 of (“000000” & parenthesized part 4 of it )) of matches (regex “(\d+).(\d+).(\d+).(\d+)”) of ((pad of it as string) of (names of (keys whose (exists value “MyStringName” whose (it as string as lowercase is “mystingvalue” of it) of it) of key “HKEY_LOCAL_MACHINE\SOFTWARE\MyCompanyKEY\MyApplicationKEY\MyVersionsKEY” of registry) as string as version)))

A: 13.15.8

T: 0.535 ms

I: singular string

//all padded and raw answers

q: (pad of it as string & " — " & it as string) of ((names of (keys whose (exists value “MyStringName” whose (it as string as lowercase is “mystingvalue” of it) of it) of key “HKEY_LOCAL_MACHINE\SOFTWARE\MyCompanyKEY\MyApplicationKEY\MyVersionsKEY” of registry)) as string as version)

A: 1.2.3.4 — 1.2.3.4

A: 13.14.15.16 — 13.14.15.16

A: 13.15.8.0 — 13.15.8

A: 3.0.0.0 — 3

A: 3.4.0.0 — 3.4

A: 9.10.11.12 — 9.10.11.12

T: 0.246 ms

I: plural string

Note: maximum of is supported in 7.1+

(imported comment written by lmpymilk91)

The padded response is working great.

I really appreciate your help you two have provided with this.

Chris