Getting False no matter the value

Hi Guys, Im trying to do something I have done before. But for some reason… Im getting always false. I think its because the value is a REG_DWORD and the relevance I’m using is for a string. any ideas?

q: value "WriteProtect" of key "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\StorageDevicePolicies" of registry
A: 1
T: 0.098 ms

q: exists key "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\StorageDevicePolicies" whose (value "WriteProtect" of it = "1") of registry
A: False
T: 0.101 ms

q: if(exists key "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\StorageDevicePolicies" whose (value "WriteProtect" of it > "0") of registry) then("Active") else("Not Active")
A: Not Active
T: 0.139 ms

q: exists value "WriteProtect" whose (it != "0") of key "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\StorageDevicePolicies" of registry
A: True
T: 0.111 ms

Sorry about it.

so I have not been able to understand the whose construct yet :persevere:

So, regarding ‘whose’ the purpose is to filter a list. The typical form/construct is:

<property> whose (condition of it) of <object>

For your specific scenario, can you try the following and see if it works?

exists key "HKLM\System\CurrentControlSet\Control\StorageDevicePolicies" whose (value "WriteProtect" of it = 1) of registry

or

exists key "HKLM\System\CurrentControlSet\Control\StorageDevicePolicies" whose (value "WriteProtect" of it = (hexadecimal integer("1"))) of registry

If it’s not clear yet, I think the problem is that you’re comparing Integers to Strings. To illustrate,

Q: 1 = "1"
Should give False (or maybe an “Incompatible Types” error)

Q: 1 as string = "1"
Should give true

Q: 1 = “1” as integer
Should give true

q: exists key "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\StorageDevicePolicies" whose (value "WriteProtect" of it as integer = 1) of registry

Should give True in your case. Note I cast the value to type Integer for comparison. You could also get true via (value "WriteProtect" of it as string = "1")

1 Like