Right, that’s the behavior I expected on the first query. I built that by taking your original, and just moving your whose()
clause to the front so instead of filtering it would just display the value on which you were trying to filter. I wanted to show how to rearrange your query to find the problem.
The second query was how to find the “real” thing.
Here’s a bit more detail to explain where the problems were.
The whole statement
(value "ImagePath" of it as string) of key of key "HKLM\SYSTEM\CurrentControlSet\Services\WinDefend" of registry
The first step retrieves a registry key
key "HKLM\SYSTEM\CurrentControlSet\Services\WinDefend" of registry
If the key exists, it is returned; if it does not exist, one would get a “Singular Expression” error. We could avoid the error and instead return an empty result if we used the plural keys
rather than key
The next step, given that key, looks for another key beneath it -
key of key "HKLM\SYSTEM\CurrentControlSet\Services\WinDefend" of registry
If there is no key beneath “WinDefend”, or more than one key beneath it, we would get another “Singular Expression” error. There might be only one key beneath it, WinDefend\Parameters
, and if that’s the case we return that key and continue.
Finally
(value "ImagePath" of it as string) of key of key "HKLM\SYSTEM\CurrentControlSet\Services\WinDefend" of registry
If we’ve made it this far, it’s trying to find an “ImagePath” value beneath `WinDefend\Parameters". Even if the service had only one subkey (Parameters), the Parameters subkey won’t have an ImagePath value beneath it (the value is at WinDefend\ImagePath, not WinDefend\Parameters\ImagePath). This expression will again throw the “Singular Expression” error because ImagePath does not exist. We could avoid the error and instead get an empty result if we used the plural ‘values of keys’ instead of ‘value of key’.