It is currently March 28th, 2024, 2:56 pm

Registry - display text if zero value

Get help with creating, editing & fixing problems with skins
Post Reply
VirtAlloc
Posts: 2
Joined: January 19th, 2023, 5:44 am

Registry - display text if zero value

Post by VirtAlloc »

I am checking regkey value for installed app version. If the regkey does not not exist, then value 0 is displayed in a meter that uses MeasureTestReg output. I want to modify the output value to "Not Installed" if the regkey does not exist. After some testing I found that IfCondition does not check string value, so the below works only if the reg value is numeric, if it is a string, then "Not Installed" is incorrectly set. What is a better way of doing this? I have tried IfMatch=0 without success

Code: Select all

[MeasureTestReg]
Measure=Registry
RegKey=SOFTWARE\WOW6432Node\TestApp
RegValue=INSTALLERVERSION
UpdateDivider=-1

[MeasureIsTestReg]
Measure=String
Format=[MeasureTestReg]
DynamicVariables=1
IfCondition=MeasureTestReg=0
IfTrueAction=[!SetOption MeterTestAppValue Text "Not Installed"]
UpdateDivider=-1
User avatar
balala
Rainmeter Sage
Posts: 16109
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Registry - display text if zero value

Post by balala »

VirtAlloc wrote: January 19th, 2023, 6:10 am I am checking regkey value for installed app version. If the regkey does not not exist, then value 0 is displayed in a meter that uses MeasureTestReg output. I want to modify the output value to "Not Installed" if the regkey does not exist. After some testing I found that IfCondition does not check string value, so the below works only if the reg value is numeric, if it is a string, then "Not Installed" is incorrectly set. What is a better way of doing this? I have tried IfMatch=0 without success
Try IfMatch=^$, obviously along with IfMatchAction=[!SetOption MeterTestAppValue Text "Not Installed"].
The ^$ expression mean that the string is empty. ^ represents the beginig, while $ is the end of the string. If the begining of the string is followed immediately by its end, the string is empty. In this case the IfMatchAction is executed, setting "Not installed" as Text of the [MeterTestAppValue] meter.
VirtAlloc
Posts: 2
Joined: January 19th, 2023, 5:44 am

Re: Registry - display text if zero value

Post by VirtAlloc »

balala wrote: January 19th, 2023, 10:36 am Try IfMatch=^$, obviously along with IfMatchAction=[!SetOption MeterTestAppValue Text "Not Installed"].
The ^$ expression mean that the string is empty. ^ represents the beginig, while $ is the end of the string. If the begining of the string is followed immediately by its end, the string is empty. In this case the IfMatchAction is executed, setting "Not installed" as Text of the [MeterTestAppValue] meter.
Hey I tried this as follows, unfortunately it displays value 0 if the key does not exist

Code: Select all

[MeasureTestReg]
Measure=Registry
RegKey=SOFTWARE\WOW6432Node\TestApp
RegValue=INSTALLERVERSION
IfMatch=^$
IfMatchAction=[!SetOption MeterTestAppValue Text "Not Installed"]
UpdateDivider=-1
User avatar
SilverAzide
Rainmeter Sage
Posts: 2588
Joined: March 23rd, 2015, 5:26 pm
Contact:

Re: Registry - display text if zero value

Post by SilverAzide »

VirtAlloc wrote: January 20th, 2023, 3:01 am Hey I tried this as follows, unfortunately it displays value 0 if the key does not exist
(P.S.: You didn't specify the RegHKey value, so it is assuming HKEY_CURRENT_USER. Is that what you want?)

If the key is not found, the registry measure will return a default value, which is 0 (and the string "0"). Testing for an empty string does not work in this case. You need to test for zero (the number, using an IfCondition) or "0" (the string, using an IfMatch). My assumption is that your original problem is that you are looking at the wrong reg hive, not that your code isn't working.
User avatar
balala
Rainmeter Sage
Posts: 16109
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Registry - display text if zero value

Post by balala »

SilverAzide wrote: January 20th, 2023, 3:23 am If the key is not found, the registry measure will return a default value, which is 0 (and the string "0"). Testing for an empty string does not work in this case. You need to test for zero (the number, using an IfCondition) or "0" (the string, using an IfMatch).
Didn't check this previously, however if you are right (and you are), there is no way to distinguish between the case in which the key doesn't exist and the case it exists, but is 0.
Post Reply