Page 1 of 1 1
Topic Options
#214224 - 2023-06-16 12:48 AM WriteValue does not modify existing value but creates a duplicate one
fobrien Offline
Just in Town

Registered: 2022-08-19
Posts: 3
Loc: France
Hello everybody,

I am posting this message as I am having some issues in order to modify an existing registry key in Windows using this code :

 Code:
$rc=WriteValue("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced","TaskbarAI","0","REG_DWORD")


Even in the great book by Bob Kelly, it is mentioned that such command is supposed to create/modify a value depending on the context.

I really do not understand the reason why I am having a duplicate key instead.
At the moment, I am trying to make it work on a Windows 10 64 bits Operating System.

Would you have any idea ?

Thanks in advance for your help.

Fred

Top
#214227 - 2023-06-16 07:44 PM Re: WriteValue does not modify existing value but creates a duplicate one [Re: fobrien]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4396
Loc: New Jersey
Welcome to KORG!

Kix is a 32-bit app, so if you're running on a 64-bit host, the O/S performs "reflection". You can disable this in Kix
 Code:
$Rc = SetOption('Explicit', 'On')
$Rc = SetOption('WrapAtEOL', 'On')
$Rc = SetOption('NoVarsInStrings', 'On')
$Rc = SetOption('NoMacrosInStrings', 'On')
$Rc = SetOption('WOW64AlternateRegView', 'Off')
The first 4 lines are recommended for good programming practices, but the last line is key to this - it disables the reflection. Try adding that line to the top of your script and see if it helps.
_________________________
Actually I am a Rocket Scientist! \:D

Top
#214232 - 2023-06-19 01:25 AM Re: WriteValue does not modify existing value but creates a duplicate one [Re: Glenn Barnas]
fobrien Offline
Just in Town

Registered: 2022-08-19
Posts: 3
Loc: France
Hi Glenn !

Thank you for your reply and this advice.
Unfortunaetely, the following code also creates a duplicate entry of the existing key already present in the system :

 Code:
$Rc = SetOption('Explicit', 'On')
$Rc = SetOption('WrapAtEOL', 'On')
$Rc = SetOption('NoVarsInStrings', 'On')
$Rc = SetOption('NoMacrosInStrings', 'On')
$Rc = SetOption('WOW64AlternateRegView', 'Off')

$Rc = WriteValue("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced","TaskbarAI","0","REG_DWORD")


Am I doing something wrong and is there another method to modify an existing registry key value ?
Is it the best way by deleting the existing registry key first, then create it afterwards, for instance ?

Thanks in advance.

Fred

Top
#214233 - 2023-06-19 03:15 AM Re: WriteValue does not modify existing value but creates a duplicate one [Re: fobrien]
Allen Administrator Offline
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4549
Loc: USA
This behavior is not normal and what you are doing is correct.

Are you saying you see TaskbarAI listed twice in HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced ?

Please provide the OS, x86 or x64, the kix version, what permissions do you have?

Top
#214234 - 2023-06-19 02:50 PM Re: WriteValue does not modify existing value but creates a duplicate one [Re: Allen]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4396
Loc: New Jersey
I just tested your code via the following steps:
1. Open a command prompt
2. Launch Regedit (my user context - NOT a local admin)
Confirm that the TaskbarAi value does not exist.
3. Create rtest.kix with "Break On" followed by your command copied/pasted.
4. Run rtest.kix - refresh RedEdit - confirmed that the TaskbarAi value is set
I'm using Kix 4.66, running an x64 platform as a non-admin user.

This worked without any issue.
It's not really possible to create two identical entries in the registry, so there needs to be some subtle difference. Spelling? Space? Special Character?

Make sure your script is saved in ANSI format, not UNICODE, delete the two values and tru your script again.
_________________________
Actually I am a Rocket Scientist! \:D

Top
#214235 - 2023-06-21 12:21 AM Re: WriteValue does not modify existing value but creates a duplicate one [Re: Glenn Barnas]
fobrien Offline
Just in Town

Registered: 2022-08-19
Posts: 3
Loc: France
Hi Glen/Allen,

Thank you for our feedback and these tests.
I feel shameful but I have eventually found what the issue was.
Indeed, when checking the registry entry from a PowerShell Terminal (I am running Windows 11 Professional 64 Bits), then I noticed that the key name was mispelled and I got confused between a capital "I" and a lower case for letter "l".
Therefore, correcting the key name dd the trick.

Image 1

Image 2

Sorry for this mistake anyway.

Fred

Top
#214236 - 2023-06-22 04:09 AM Re: WriteValue does not modify existing value but creates a duplicate one [Re: fobrien]
Allen Administrator Offline
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4549
Loc: USA
All good. Happens to the best of us.
Top
Page 1 of 1 1


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 370 anonymous users online.
Newest Members
Timothy, Jojo67, MaikSimon, kvn317, kixtarts2025
17874 Registered Users

Generated in 0.058 seconds in which 0.027 seconds were spent on a total of 13 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org