#214200 - 2023-02-20 10:50 PM
Kixtart cannot create a blank/null registry value
|
Robdutoit
Hey THIS is FUN
Registered: 2012-03-27
Posts: 363
Loc: London, England
|
Function CheckAndSetRegValue($RegPath, $RegValue, $RegData, $RegType)
$ReturnValue = ReadValue($RegPath, $RegValue)
If ($ReturnValue = $RegData)
? "Registry value already applied"
Else
WriteValue($RegPath, $RegValue, $RegData, $RegType)
? "Registry value is being set for: "
EndIf
EndFunction
CheckAndSetRegValue($PCSoftware + "\Policies\Mozilla\Firefox", "OverrideFirstRunPage", "", "REG_SZ")
I want the data field of the Registry Value OverrideFirstRunPage to be empty/blank/null. However, I have to put a space in between the apostrophes, otherwise the registry entry is not added. Is there some way to get Kixtart to create a registry value with no data.
https://admx.help/?Category=Firefox&Policy=Mozilla.Policies.Firefox::OverrideFirstRunPage
|
Top
|
|
|
|
#214203 - 2023-02-22 12:36 PM
Kixtart can't create empty data in registry
|
Robdutoit
Hey THIS is FUN
Registered: 2012-03-27
Posts: 363
Loc: London, England
|
;============================================================================================================
; Checks the registry VALUE and if incorrect, it applies correct setting, otherwise says already applied
;============================================================================================================
Function CheckAndSetRegValue($RegPath, $RegValue, $RegData, $RegType)
$ReturnValue = ReadValue($RegPath, $RegValue)
If ($ReturnValue = $RegData)
? "Registry value already applied"
Else
WriteValue($RegPath, $RegValue, $RegData, $RegType)
? "Registry value is being set for: "
EndIf
EndFunction
CheckAndSetRegValue($PCSoftware + "\Policies\Mozilla\Firefox", "OverrideFirstRunPage", "", "REG_SZ")
The data field for the Registry Value "OverrideFirstRunPage" is null or empty. However, Kixtart will not create the value if the data field is empty. I have to put in at least a space, which is incorrect as a space is something, whereas the data field needs to be null.
I posted this a couple of days ago. But for some reason, my post vanished into thin air. It might be because I logged out immediately after posting. This time I will try waiting until it goes back to the previous page!
|
Top
|
|
|
|
#214206 - 2023-02-22 04:25 PM
Re: (NA) Kixtart can't create empty data in registry
[Re: Glenn Barnas]
|
ShaneEP
MM club member
Registered: 2002-11-29
Posts: 2125
Loc: Tulsa, OK
|
The below seems to work fine for me as well. With no space required in the data field to create the value.
$nul = writevalue("HKEY_CURRENT_USER\Test", "OverrideFirstRunPage", "", "REG_SZ")
|
Top
|
|
|
|
#214208 - 2023-02-22 10:49 PM
Re: (NA) Kixtart can't create empty data in registry
[Re: Robdutoit]
|
Glenn Barnas
KiX Supporter
Registered: 2003-01-28
Posts: 4396
Loc: New Jersey
|
The general rule for Parens is:
STATEMENTS (ie: Kix COMMANDS) do not require parenthesis and generally do not return data but may return status via @ERROR/@SERROR (see MD and RD for exaples). A Statement may take args in a specific syntax. IF is a statement.
FUNCTIONS always require parenthesis, and can return both Values and Result Codes. A value is returned when you call a function as $V = Function(arg). The result code is returned by @ERROR.
Most functions that I write return a value (use an array if you need to return multiple values values) and the result code. If the function performs an action and doesn't need to return data, I generally return "1" and Exit 0 on success and return "0" and Exit # on failure. This allows me to use If Function(data)
'SUCCESS!' @CRLF
Else
'Error in function - ' @SERROR @CRLF
EndIf As for item "C" - if you don't use $Rc = func(), the regurn codes just fall out all over the screen, leaving a trail of numbers. It isn't required, but is good practice.
As for debugging messages, see my fMsg() function. Declare the following:Global $DEBUG
$DEBUG = 1 ; set to non-zero when debugging
fMsg('this is an always visible message', '', 0, 0)
fMsg('This is a debug message...', '', 0, 4) The first message is always output, while the second message is displayed only when $DEBUG is non-zero. You can even define various levels of debugging, so if DEBUG is 1, you get some messages, DEBUG=2 you get more, and DEBUG=3 you get a lot.
By using fMsg() you can sprinkle debug messages throughout your application and turn them on/off by simply changing the Global $DEBUG value rather than searching your code and removing or commenting out message lines.
_________________________
Actually I am a Rocket Scientist!
|
Top
|
|
|
|
#214209 - 2023-02-23 01:14 PM
Re: (NA) Kixtart can't create empty data in registry
[Re: Glenn Barnas]
|
Robdutoit
Hey THIS is FUN
Registered: 2012-03-27
Posts: 363
Loc: London, England
|
Do you get your skills at Kixtart from being a Rocket Scientist! You seem to know so much.
It probably is because I don't do coding for a living - my main job - I almost never do coding. I only use it for Kixtart, but I am still amazed how after nearly 20 years of using Kixtart, I am still learning things! But then again, all my "coding skills" has been self taught - never did a formal course.
I will review your points on parenthesis, however I will balance that with making the script as readable as possible. For example it is not strictly necessary to do this:
If abc = 5
Indent this line of code
Else
Indent this line of code
Endif
but so much easier to read than this when you have lots of code between the IF/Else/Endif statements or when you have multiple if/else statements within other If/Else statements:
If abc = 5
No Indent this line of code
Else
No Indent this line of code
Endif
I probably could remove the "registry value added" output as that was put in years ago when I was configuring dozens of registry entries and it helped to ensure that all registry values were actually being set. Didn't think to use it this time as I assumed the problem was Kixtart not being able to declare a null data value! Ironic. I like the idea of your debugging code.
When I have time, I will tweak my coding accordingly.
|
Top
|
|
|
|
#214210 - 2023-02-23 02:42 PM
Re: (NA) Kixtart can't create empty data in registry
[Re: Robdutoit]
|
Glenn Barnas
KiX Supporter
Registered: 2003-01-28
Posts: 4396
Loc: New Jersey
|
No - the skills come from writing Kix code every day to production level standards that we use for all of our development in Kix, C++, Python, and other languages. About 70% of our production / commercial code is written in Kix because it has no endpoint dependencies, produces tiny code, and is trivial to self-update via the web. Our Kix UDF library now contains over 750 discrete functions. We run Kix-based Windows Services, make API calls to multiple platforms to perform all manner of automated processing and endpoint monitoring.
I have an "Intro to Programming" course I used to teach at the local college adult-ed division. It featured Kix, but concepts apply to most languages. You can download it from https://www.barnas.us/programming where you will also find KGen (script link-editor), the KGen user guide, and my recent Kix UDF library.
Using parenthesis is not related to indenting code blocks, for which we always use 2 spaces per level as full tabs look horrible in complex code. See any of my posted UDFs for examples.
Your original function should use Exit 0 on success and Exit 1 on failure. You can use other codes to exit when appropriate, such as "2" for "not found". I would also use $FnName = 1 on success and $FnName = 0 on failure ($FnName is the actual name of your function). This allows you to easily check the response with If Not MyFunc($Var)
'Function failed: ' @SERROR @CRLF
; possible recovery or second attempt
EndIf This is where you would put your messages, rather than in the function. The function tells your main code if it was successful, and if not, the Error code tells it why it failed. We often use negative return codees (Exit -1) to report custom errors.
_________________________
Actually I am a Rocket Scientist!
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 393 anonymous users online.
|
|
|