Relevance for Windows Update settings

Hi

I am trying to create av property that will find the windows update setting in the registry. The problem is there are different places in the registry that tell the setting on different servers. I have created 3 statements for this.

  1. Value of AUOptions in key HKEY_LOCAL_MACHINE\Software\Policies\Microsoft\Windows\WindowsUpdate\AU

  2. Value of AUOptions in key HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update

  3. IF none of the 2 keys above exist and there exists a key HKEY_LOCAL_MACHINE\Software\Policies\Microsoft\Windows\WindowsUpdate\AU with value NoAutoUpdate = 1.

Building of @strawgate’s existing relevance query for this i created this

if exists (value “AUOptions” of key “HKEY_LOCAL_MACHINE\Software\Policies\Microsoft\Windows\WindowsUpdate\AU” of native registry) then (if(it = “1”) then (“Never check for updates.”) else (if(it = “2”) then (“Notify before download.”) else (if (it = “3”) then (“Automatically download and notify of installation.”) else (if (it = “4”) then “Automatic download and scheduled installation” else (if (it = “5”) then “Automatic Updates is required, but end users can configure it.” else “Value not recognized”))))) of (value “AUOptions” of key “HKEY_LOCAL_MACHINE\Software\Policies\Microsoft\Windows\WindowsUpdate\AU” of native registry as string)

else if exists (value “AUOptions” of key “HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update” of native registry) then (if(it = “1”) then (“Never check for updates.”) else (if (it = “2”) then (“Notify before download.”) else (if (it = “3”) then (“Automatically download and notify of installation.”) else (if (it = “4”) then “Automatic download and scheduled installation” else (if (it = “5”) then “Automatic Updates is required, but end users can configure it.” else “Value not recognized”))))) of (value “AUOptions” of key “HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update” of native registry as string)

else if not exists (value “AUOptions” of key “HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update” of native registry) and not exists (value “AUOptions” of key “HKEY_LOCAL_MACHINE\Software\Policies\Microsoft\Windows\WindowsUpdate\AU” of native registry) and exists key “HKEY_LOCAL_MACHINE\Software\Policies\Microsoft\Windows\WindowsUpdate\AU” whose (value “NoAutoUpdate” of it as integer = 1) of native registry then “Never check for updates.”

else “N/A”

When i run on servers that fit the first if clause i get the intended result, but when they shoul hit the later if clauses it gets “Singular expression refers to nonexistent object.” I have tested this by running the relevance query torwards 1 statement and this works. This makes me think there is something wrong with the if structure. Does anyone have any tips?

1 Like

Hi!

There are some easiest ways to approach this problem that might simplify this solution.

The first is the error pipe. We can use, “|” to go to the next statement in the case of an error. So if you have a hierarchy of values where you want 1, if 1 doesn’t exist you want 2, if 2 doesn’t exist you want 3, you can just do:

value "AUOptions" of key "HKEY_LOCAL_MACHINE\Software\Policies\Microsoft\Windows\WindowsUpdate\AU" of native registry | value "AUOptions" of key "HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update" of native registry | value "AUOptions" of key "HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update" of native registry

From here we can convert it to an integer:

((value "AUOptions" of key "HKEY_LOCAL_MACHINE\Software\Policies\Microsoft\Windows\WindowsUpdate\AU" of native registry | value "AUOptions" of key "HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update" of native registry | value "AUOptions" of key "HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update" of native registry) as integer)

And instead of doing a big if then else statement to convert that integer into a string we can use a “Tuple String Item”

How Tuple String items work is that if I have a string:

"Test, Test1, Test2"

If I do,

tuple string item 0 of "Test, Test1, Test2"

I would get “Test” as a result.

tuple string item 1 of "Test, Test1, Test2"

Would return “Test1”

So next we assemble your strings into a tuple:

(", Never check for updates, Notify before download, Automatically download and notify of installation, Automatic download and scheduled installation. Automatic updates is required but end users can configure it")

I don’t believe this value can be 0 so the first , is saying that tuple string 0 should be an empty string.

This leaves us with the following relevance:

tuple string item ((value "AUOptions" of key "HKEY_LOCAL_MACHINE\Software\Policies\Microsoft\Windows\WindowsUpdate\AU" of native registry | value "AUOptions" of key "HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update" of native registry | value "AUOptions" of key "HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update" of native registry) as integer) of (", Never check for updates, Notify before download, Automatically download and notify of installation, Automatic download and scheduled installation. Automatic updates is required but end users can configure it")
3 Likes

Thanks, this works very well! So the tuple works kind of like a simple array if i understand correctly. I have a question about the error pipe “|”. Is there a reason to use if, else if, else structure when you can use “|”? Do you know the main differences / use cases for them?

From a technical standpoint the “|” operator only supports singular objects. This means it’s great for getting a single value or checking the existence of a single key at a time. It is not however useful in a scenario where you need a plural think:

values of key "HKEY_LOCAL_MACHINE\Software\Policies\Microsoft\Windows\WindowsUpdate\AU" of native registry | values of key "HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update" of native registry
1 Like

Okay, then i understand. Thanks for the help!