Installed App Version Issue

I am trying to build an analysis that detects and returns installed app versions for specific apps. I am successful when only one statement is made but when I try to add an OR statement for possible different installed versions I get an error that, “A Boolean expression is required.” I am not certain why this is since I am asking the same question just with a different place to look for the same data. I have included my examples below. Any help is greatly appreciated!

Works:

q: (if (exists key "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{1A3CD9C5-7A1D-4349-8AE7-5A620C2BF80D}" whose (exists value "DisplayName" of it) of registry) then (value "DisplayName" of key "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{1A3CD9C5-7A1D-4349-8AE7-5A620C2BF80D}" of registry as string) else "Not Installed")
A: Not Installed
T: 0.109 ms

Doesn’t work:

q: (if (exists key "HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Installer\Products\B09BD3CE447C57A4B9BA75D56F0C18A6" whose (exists value "ProductName" of it) of registry) then (value "ProductName" of key "HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Installer\Products\B09BD3CE447C57A4B9BA75D56F0C18A6" of registry as string) else "Not Installed") OR (if (exists key "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{1A3CD9C5-7A1D-4349-8AE7-5A620C2BF80D}" whose (exists value "DisplayName" of it) of registry) then (value "DisplayName" of key "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{1A3CD9C5-7A1D-4349-8AE7-5A620C2BF80D}" of registry as string) else "Not Installed")
E: A boolean expression is required.

I have also moved the “else” statement around thinking that was causing the issue but I have not found the proper syntax.

The issue here is you can only use an OR statement between two boolean items:

<boolean> OR <boolean>

The same is with AND

<boolean> AND <boolean>

The issue is that when you boil down your query:

(if (exists key "HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Installer\Products\B09BD3CE447C57A4B9BA75D56F0C18A6" whose (exists value "ProductName" of it) of registry) then (value "ProductName" of key "HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Installer\Products\B09BD3CE447C57A4B9BA75D56F0C18A6" of registry as string) else "Not Installed")

This will return a string, and your next part:

(if (exists key "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{1A3CD9C5-7A1D-4349-8AE7-5A620C2BF80D}" whose (exists value "DisplayName" of it) of registry) then (value "DisplayName" of key "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{1A3CD9C5-7A1D-4349-8AE7-5A620C2BF80D}" of registry as string) else "Not Installed")

You’re trying to do <string> OR <string> which doesn’t work in this case.

For what you’re trying to do you can put a semicolon between them to return both but we can simplify your relevance tremendously and maybe achieve a couple goals.

First, instead of returning “ProductName” and, “Not Installed”, you should really return the Product name if it’s installed and nothing if it’s not installed.

values "ProductName" of keys "HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Installer\Products\B09BD3CE447C57A4B9BA75D56F0C18A6" of registry

If we use plurals here, values instead of value and keys instead of key then if the key or product name doesn’t exist, it’ll return nothing instead of an error. See:

Q: keys "HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Installer\Products\B09BD3CE447C57A4B9BA75D56F0C18A6" of registry
T: 0.082 ms

Q: key "HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Installer\Products\B09BD3CE447C57A4B9BA75D56F0C18A6" of registry
E: Singular expression refers to nonexistent object.

Because we don’t get an error, we don’t have to do any error handling which significantly simplifies the relevance.

Finally, we can get both values by putting the semicolon between them:

values "ProductName" of keys "HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Installer\Products\B09BD3CE447C57A4B9BA75D56F0C18A6" of registry;values "DisplayName" of keys "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{1A3CD9C5-7A1D-4349-8AE7-5A620C2BF80D}" of registry
2 Likes

Excellent advice! Thank you very much for your time!