Return true if registry key doesn't exist or the value comparison succeeds

Can someone please help me clean this up…I’ve looked at various posts that are doing similar checks, but can’t find one that matches my issue. And I can’t seem to get my “it clauses” correct in the fixlet debugger.

Basically, I want to return true if 1) the key doesn’t exist or 2) the key exists but it is a previous version.

The relevance below works, I just want to replace the duplication of the registry key with an “it”.

(not exists key "HKLM\Software\Microsoft\Windows\CurrentVersion\Uninstall\{D929B3B5-56C6-46CC-B3A3-A1A784CBB8E4}" of native registry) or (exists values whose (name of it as string as lowercase is "displayversion" and pad of (it as string as version) < "10.3.15") of keys "HKLM\Software\Microsoft\Windows\CurrentVersion\Uninstall\{D929B3B5-56C6-46CC-B3A3-A1A784CBB8E4}" of native registry)

Try this:

not exists values "DisplayVersion" whose( ( pad of (it as string as version) ) >= "10.3.15" ) of keys "HKLM\Software\Microsoft\Windows\CurrentVersion\Uninstall\{D929B3B5-56C6-46CC-B3A3-A1A784CBB8E4}" of (x64 registries; x32 registries)

What is the DisplayName of this software?

I personally prefer to use the DisplayName instead of hard coding the GUID because the GUID can change.

See this example: https://bigfix.me/fixlet/details/3900

Specifically, this relevance: https://bigfix.me/relevance/details/2999444

This is the general form for the relevance I use for all windows software for installation OR updating:

not exists keys whose(value "DisplayName" of it as string as trimmed string starts with "DISPLAYNAME_OF_APP" AND value "DisplayVersion" of it as string as version >= "DISPLAYVERSION_OF_APP") of keys "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall" of (x64 registries; x32 registries)

If you wanted relevance to use for Updating / patching ONLY:

exists keys whose(value "DisplayName" of it as string as trimmed string starts with "DISPLAYNAME_OF_APP" AND value "DisplayVersion" of it as string as version < "DISPLAYVERSION_OF_APP") of keys "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall" of (x64 registries; x32 registries)

Just replace DISPLAYNAME_OF_APP and DISPLAYVERSION_OF_APP with the values from the version you are installing.

2 Likes

Thanks for coming through again, James. Great tip about using the DisplayName instead of the GUID. But wouldn’t that incur additional cost since it has to look at all the keys and values of every key under HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall while it looks for a match, instead of looking only under a single key like the first example with the GUID does? Or am I misunderstanding how this works?

You are correct, there is an additional penalty. There is a way to write it to reduce the penalty, but only if the DisplayName is exactly matched and does not change, which is not always the case.

The penalty is actually very minor due to registry read operations being extremely fast. This is a case where I feel that having the relevance be less efficient is acceptable if it allows for that relevance to be used in nearly all cases with very minor modifications.

Your computer is doing 1000’s of registry read operations every minute. Run Process Monitor and see. I’d bet the registry is cached in RAM for reads.

In the debugger, the process of reading all of the entries in the uninstall keys of the registries is only about 2ms.

Great, thanks again. Yeah, watching Process Monitor as your PC is seemingly doing nothing is very enlightening. :smile:

1 Like

This is exactly what I needed, you are awesome

This worked. Thank you