It is currently February 23rd, 2024, 2:24 am

A question about "Registry Measure"

Report bugs with the Rainmeter application and suggest features.
User avatar
Lssg97
Posts: 36
Joined: October 21st, 2018, 2:55 am

A question about "Registry Measure"

Post by Lssg97 »

Hi guys,

I want to give a feedback about the use of "Registry Measure".

When I use "Measure=Registry", if the content I want to detect is a key or value that does not exist in the registry, Measure will return the number "0" and the string "0". But I cannot use "IfMatch=^0$" to perform related judgment operations, as if it is invalid.

In addition, I also found that if I want to use the Bang "!SetOption" to change "RegKey" in the Registry Measure, if I switch from a key that exists in the registry to a key that does not exist, the value returned by the Measure will not change or become "0". If the value exists in the registry, it can be changed normally.

I am not sure if the situation mentioned above is a problem with the registry itself or a bug in Rainmeter. Hope to get an answer.

Thank you!
User avatar
balala
Rainmeter Sage
Posts: 16007
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: A question about "Registry Measure"

Post by balala »

Lssg97 wrote: November 26th, 2020, 10:41 am When I use "Measure=Registry", if the content I want to detect is a key or value that does not exist in the registry, Measure will return the number "0" and the string "0". But I cannot use "IfMatch=^0$" to perform related judgment operations, as if it is invalid.
Try to use IfMatch=0.
Lssg97 wrote: November 26th, 2020, 10:41 am In addition, I also found that if I want to use the Bang "!SetOption" to change "RegKey" in the Registry Measure, if I switch from a key that exists in the registry to a key that does not exist, the value returned by the Measure will not change or become "0". If the value exists in the registry, it can be changed normally.
I think it does work. See the code of the following Registry measure:

Code: Select all

[MeasureWindowsVersion]
Measure=Registry
RegHKey=HKEY_LOCAL_MACHINE
RegKey=Software\Microsoft\Windows NT\CurrentVersion
;RegValue=ProductName
As you can see I commented out the RegValue option and this will be set immediatelly by a !SetOption bang (see the whole code below). If I set a valid RegValue through a !SetOption bang, the measure returns the appropriate value, read from the registry. If the set RegValue is not valid, the measure returns 0 and this even dynamically.
So here is the whole code of the skin I used:

Code: Select all

[Rainmeter]
DynamicWindowSize=1
AccurateText=1

[Variables]
MyVar=1

[MeasureMyVar]
Measure=Calc
Formula=#MyVar#
IfCondition=(#CURRENTSECTION#=0)
IfTrueAction=[!SetOption MeasureWindowsVersion RegValue "ProducteName"][!UpdateMeasure "MeasureWindowsVersion"]
IfFalseAction=[!SetOption MeasureWindowsVersion RegValue "ProductName"][!UpdateMeasure "MeasureWindowsVersion"]
DynamicVariables=1

[MeasureWindowsVersion]
Measure=Registry
RegHKey=HKEY_LOCAL_MACHINE
RegKey=Software\Microsoft\Windows NT\CurrentVersion
;RegValue=ProductName
IfMatch=0
IfMatchAction=[!SetOption MeterString FontColor "0,255,0"][!UpdateMeter "MeterString"][!Redraw]
IfNotMatchAction=[!SetOption MeterString FontColor "255,0,0"][!UpdateMeter "MeterString"][!Redraw]

[MeterString]
Meter=STRING
MeasureName=MeasureWindowsVersion
X=0
Y=0
Padding=15,5,15,5
FontColor=220,220,220
FontEffectColor=0,0,0
StringEffect=Shadow
SolidColor=0,0,0,150
FontSize=8
FontFace=Segoe UI
StringStyle=BOLD
StringAlign=LEFT
AntiAlias=1
Text=%1
DynamicVariables=1
LeftMouseUpAction=[!SetVariable MyVar "(1-#MyVar#)"][!UpdateMeasure "MeasureMyVar"]
See that when you click the string (which is showing the value returned by the Registry measure), the value of the MyVar variable is changing from 0 to 1 (or vice-versa). The RegValue of the [MeasureWindowsVersion] measure is set accordingly and the color of the [MeterString] meter is set as well.
User avatar
Lssg97
Posts: 36
Joined: October 21st, 2018, 2:55 am

Re: A question about "Registry Measure"

Post by Lssg97 »

balala wrote: November 26th, 2020, 11:17 am I think it does work. See the code of the following Registry measure:
Hi balala,

First of all thank you for your answers. The content you showed works perfectly, but it is a little different from what I encountered.

According to the user manual, if not specified "RegValue", the default value is retrieved. Every existing Key in the registry contains a default value, even if no value is set, it is existing in the registry . But if the content I want to retrieve does not have a corresponding Key in the registry, I will encounter the problem I have reported above.

I have modified two lines of content based on your code. You can try the effect of the following skin to understand the problem I encountered.

Code: Select all

[Rainmeter]
DynamicWindowSize=1
AccurateText=1

[Variables]
MyVar=1

[MeasureMyVar]
Measure=Calc
Formula=#MyVar#
IfCondition=(#CURRENTSECTION#=0)
IfTrueAction=[!SetOption MeasureWindowsVersion RegKey "Software\Microsoft\Windows NT\CurrentVersion"][!UpdateMeasure "MeasureWindowsVersion"]
IfFalseAction=[!SetOption MeasureWindowsVersion RegKey "Software\Microsoft\Windows NT\CurrentVersion2"][!UpdateMeasure "MeasureWindowsVersion"]
DynamicVariables=1

[MeasureWindowsVersion]
Measure=Registry
RegHKey=HKEY_LOCAL_MACHINE
RegKey=Software\Microsoft\Windows NT\CurrentVersion
RegValue=ProductName
IfMatch=0
IfMatchAction=[!SetOption MeterString FontColor "0,255,0"][!UpdateMeter "MeterString"][!Redraw]
IfNotMatchAction=[!SetOption MeterString FontColor "255,0,0"][!UpdateMeter "MeterString"][!Redraw]

[MeterString]
Meter=STRING
MeasureName=MeasureWindowsVersion
X=0
Y=0
Padding=15,5,15,5
FontColor=220,220,220
FontEffectColor=0,0,0
StringEffect=Shadow
SolidColor=0,0,0,150
FontSize=8
FontFace=Segoe UI
StringStyle=BOLD
StringAlign=LEFT
AntiAlias=1
Text=%1
DynamicVariables=1
LeftMouseUpAction=[!SetVariable MyVar "(1-#MyVar#)"][!UpdateMeasure "MeasureMyVar"]
Last edited by Lssg97 on November 27th, 2020, 4:46 pm, edited 1 time in total.
User avatar
balala
Rainmeter Sage
Posts: 16007
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: A question about "Registry Measure"

Post by balala »

Lssg97 wrote: November 26th, 2020, 4:03 pm According to the user manual, if not specified "RegValue", the default value is retrieved. Every existing Key in the registry contains a default value, even if no value is set, it is existing in the registry . But if the content I want to retrieve does not have a corresponding Key in the registry, I will encounter the problem I have reported above.

I have modified two lines of content based on your code. You can try the effect of the following skin to understand the problem I encountered.
Yep, right. Unfortunatelly there probably is no solution for your problem, because if you're switching from an existent key to a non-existent, the Registry measure keeps returning the last valid value, so the last existing value. There are more such behaviours of Rainmeter in some circumstances.
This definitely isn't exactly the same question, but a similar question arose a while ago. Then brian (who is a developer) explained a few things about how things are working in Rainmeter, something similar should be the explanation here as well.
User avatar
Lssg97
Posts: 36
Joined: October 21st, 2018, 2:55 am

Re: A question about "Registry Measure"

Post by Lssg97 »

balala wrote: November 26th, 2020, 4:29 pm This definitely isn't exactly the same question, but a similar question arose a while ago. Then brian (who is a developer) explained a few things about how things are working in Rainmeter, something similar should be the explanation here as well.
Okay, I got it. Maybe the truth is like what Brian said. It looks like Rainmeter treats non-existent registry keys as invalid inputs. I originally thought that Measure could return an empty string for a non-existent registry key, but it would be a pity if not.

Thanks again for your answers. :rosegift:
User avatar
balala
Rainmeter Sage
Posts: 16007
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: A question about "Registry Measure"

Post by balala »

Lssg97 wrote: November 26th, 2020, 5:17 pm Okay, I got it. Maybe the truth is like what Brian said. It looks like Rainmeter treats non-existent registry keys as invalid inputs. I originally thought that Measure could return an empty string for a non-existent registry key, but it would be a pity if not.

Thanks again for your answers. :rosegift:
I'm glad if you got an answer to your question, even if it's not exactly what have you expected.
RicardoTM
Posts: 124
Joined: December 28th, 2022, 9:30 pm
Location: México

Re: A question about "Registry Measure"

Post by RicardoTM »

Sorry for reviving this old post. Maybe 3 years ago there wasn't some trick to work around this.

I'm currently facing the exact same problem. I want to deactivate measures based on their string value. These measures are HWiNFO registry measures.

At first I thought I could do something like IfMatch=^0$ but noup, it doesn't work. Then I thought well, I use substitute to replace that 0 for some string and then use ifMatch with that string but noup, it doesn't work. If I use something like IfMatch=0 then it would disable even if the string is "0 RPM" which is not the desired behavior.

I'm facing a big wall right now. The only thing that works is using ifcondition, and it works only because the string value becomes a "flat" number only when there's no sensor active, but that gives me an ifcondition error on the log when it's false.

I'm looking for ideas on how to address this. The idea is that the measures are disabled until the user sets the index values through a settings panel, but if the use later on "deletes" that index value the measure would disable until a new index value is set. When I say "delete" what happens is that the index value is replaced by the word "INDEX", which is an invalid index value, which turns the string value of the measure into a 0. The only time these measures are 0 is when there's no valid index value. This is to avoid the measure from disabling with values like 0 V, 0 W, 0 RPM.

Any idea on how to solve this issue?

Edit: Lol, right after writing this I realized I can use the variables I use to set the index values to deactivate them, changing those variables to "-1" instead of "INDEX" allows me to use ifconditions to deactivate them using only one measure:

Code: Select all

[SensorDisabler]
Group=ListSensors
Measure=Calc
IfCondition=([#Sensor1Ix] = -1)
IfTrueAction=[!DisableMeasure mSensor1]
IfFalseAction=[!EnableMeasure mSensor1]
IfCondition2=([#Sensor2Ix] = -1)
IfTrueAction2=[!DisableMeasure mSensor2]
IfFalseAction2=[!EnableMeasure mSensor2]
IfCondition3=([#Sensor3Ix] = -1)
IfTrueAction3=[!DisableMeasure mSensor3]
IfFalseAction3=[!EnableMeasure mSensor3]
IfCondition4=([#Sensor4Ix] = -1)
IfTrueAction4=[!DisableMeasure mSensor4]
IfFalseAction4=[!EnableMeasure mSensor4]
IfCondition5=([#Sensor5Ix] = -1)
IfTrueAction5=[!DisableMeasure mSensor5]
IfFalseAction5=[!EnableMeasure mSensor5]
IfCondition6=([#Sensor6Ix] = -1)
IfTrueAction6=[!DisableMeasure mSensor6]
IfFalseAction6=[!EnableMeasure mSensor6]
DynamicVariables=1
Hope this solution serves anyone else having this problem.
User avatar
Yincognito
Rainmeter Sage
Posts: 6781
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: A question about "Registry Measure"

Post by Yincognito »

RicardoTM wrote: February 11th, 2024, 8:14 pmAt first I thought I could do something like IfMatch=^0$ but noup, it doesn't work. Then I thought well, I use substitute to replace that 0 for some string and then use ifMatch with that string but noup, it doesn't work. If I use something like IfMatch=0 then it would disable even if the string is "0 RPM" which is not the desired behavior.
For anyone reading this in the future, here's one way for IfMatch to deal with valid / existing and invalid / inexistent registry values:

Code: Select all

[Variables]
RegValue0=ProductName
RegValue1=Bla-Bla-Bla
Index=0
Rating=Valid = Yeah

[Rainmeter]
Update=1000
AccurateText=1
DynamicWindowSize=1
BackgroundMode=2
SolidColor=0,255,0,255

---Measures---

[Value]
Measure=Registry
RegHKey=HKEY_LOCAL_MACHINE
RegKey=Software\Microsoft\Windows NT\CurrentVersion
RegValue=[#RegValue[#Index]]
IfMatch=^.{1,}$
IfMatchAction=[!SetVariable Rating "Valid = Yeah"]
IfNotMatchAction=[!SetVariable Rating "Valid = Nope"]
DynamicVariables=1

---Meters---

[Result]
Meter=String
AntiAlias=1
Text=[#RegValue[#Index]] = [Value] (#Rating#)
LeftMouseUpAction=[!SetVariable Index (1-#Index#)][!UpdateMeasure Value][!UpdateMeter Result][!Redraw]
DynamicVariables=1
This approaches things the other way around, i.e. instead of testing whether the value is not existing via the ^$ or ^0$ regex patterns, it tests whether the value exists aka it has more than one character in length. It also avoids the need to check for a "0" value which might very well be valid and existing, not to mention being confusing in terms of the equivalence involved.
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth
RicardoTM
Posts: 124
Joined: December 28th, 2022, 9:30 pm
Location: México

Re: A question about "Registry Measure"

Post by RicardoTM »

Yincognito wrote: February 11th, 2024, 10:27 pm For anyone reading this in the future, here's one way for IfMatch to deal with valid / existing and invalid / inexistent registry values:

Code: Select all

[Variables]
RegValue0=ProductName
RegValue1=Bla-Bla-Bla
Index=0
Rating=Valid = Yeah

[Rainmeter]
Update=1000
AccurateText=1
DynamicWindowSize=1
BackgroundMode=2
SolidColor=0,255,0,255

---Measures---

[Value]
Measure=Registry
RegHKey=HKEY_LOCAL_MACHINE
RegKey=Software\Microsoft\Windows NT\CurrentVersion
RegValue=[#RegValue[#Index]]
IfMatch=^.{1,}$
IfMatchAction=[!SetVariable Rating "Valid = Yeah"]
IfNotMatchAction=[!SetVariable Rating "Valid = Nope"]
DynamicVariables=1

---Meters---

[Result]
Meter=String
AntiAlias=1
Text=[#RegValue[#Index]] = [Value] (#Rating#)
LeftMouseUpAction=[!SetVariable Index (1-#Index#)][!UpdateMeasure Value][!UpdateMeter Result][!Redraw]
DynamicVariables=1
This approaches things the other way around, i.e. instead of testing whether the value is not existing via the ^$ or ^0$ regex patterns, it tests whether the value exists aka it has more than one character in length. It also avoids the need to check for a "0" value which might very well be valid and existing, not to mention being confusing in terms of the equivalence involved.
Works perfectly. :thumbup: Thanks Yin Sensei.
User avatar
Yincognito
Rainmeter Sage
Posts: 6781
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: A question about "Registry Measure"

Post by Yincognito »

RicardoTM wrote: February 11th, 2024, 11:41 pm Works perfectly. :thumbup: Thanks Yin Sensei.
Image
:great:
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth