Get DisplayVersion from Registry by Publisher

Hi,

I’m trying to get some application data from the registry, and as usual, it is not working. This is what I usually use, but its not cutting it today. What am I doing wrong?

version of key whose (value “Publisher” of it as string equals “StataCorp LLC” of (value “DisplayVersion” of it as string as version)) of key “HKLM\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall” of native registry

The “version of regapp “C:\Program Files\program.exe”” approach does not produce any output.

Hey Jason! Fancy seeing you here…

I think the problem is that the thing you’re asking for in your relevance is the version of the key, rather than the value of the DisplayVersion, which should come first. I rewrote it a bit and tested it on Box Sync, since I don’t have Stata installed, and this returns the value of DisplayVersion as a string. I think your other problem might have been the “as string as version” part.

value "DisplayVersion" of key whose (value "Publisher" of it as string equals "Box Inc.") of key "HKLM\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall" of native registry

If you change “Box Inc.” to “StataCorp LLC” I think it should work. Also worth mentioning that if there’s more than one key with “StataCorp LLC” as its Publisher, you can just pluralize “values” and “keys” and it’ll report all of them (which you’ll probably want to concatenate or whatever)

Thanks Adam! I’ll try that out.

That did it. Thanks!

This part is technically incorrect and will not work on 32bit machines. Instead do it like this:

unique values of (it as string as version) of values "DisplayVersion" of keys whose(exists values "Publisher" whose(it as string = "StataCorp LLC") of it) of keys "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall" of (x64 registries; x32 registries)

This is the general form I use for everything comming from the Uninstall key of the registry and is the form I would always recommend using.


Also, I consider it a best practice to always use Plural Relevance and not Singular Relevance. There is a trick to converting a singular relevance statement to a plural one when doing comparisons, but it is almost always the better method.

Example:

Instead of this:

@jasonrw

3 Likes

How would we throw an “if, then, else” phrase in here? Trying:

if exists “HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Maple 2017” then unique values of (it as string as version) of values “DisplayVersion” of keys whose(exists values “Publisher” whose(it as string = “Maplesoft”) of it) of keys “HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall” of (x64 registries; x32 registries) else “Not installed”

…doesn’t work.

Probably doesn’t work because you are doing

if <condition> then <version> else <string>

and your then/else need to return the same thing usually. Also your conditions aren’t really the same as in one you check for a hard key then the other you check for the Publisher to match.

Would if = # of then display else “Not installed” work?

No. You could cast the version to a string, or put “nothing” in the Else block, or possibly send an error message.

if exists "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Maple 2017" then unique values of (it as string) of values "DisplayVersion" of keys whose(exists values "Publisher" whose(it as string = "Maplesoft") of it) of keys "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall" of (x64 registries; x32 registries) else "Not installed"

or

if exists "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Maple 2017" then unique values of (it as string as version) of values "DisplayVersion" of keys whose(exists values "Publisher" whose(it as string = "Maplesoft") of it) of keys "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall" of (x64 registries; x32 registries) else nothing

Or (maybe, test this out)

if exists "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Maple 2017" then unique values of (it as string as version) of values "DisplayVersion" of keys whose(exists values "Publisher" whose(it as string = "Maplesoft") of it) of keys "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall" of (x64 registries; x32 registries) else error "Not installed"

Thanks! I’ll give this a try.