MattHiggs Posted November 17, 2025 Posted November 17, 2025 (edited) Hello Everyone. I want to automate the configuration of certain taskbar settings when a user logs into their machine. I have found a powershell script which shows me how to modify the registry to achieve my goal, however, part of the process involves reading and modifying binary. Consider the below powershell code: $settingKey = 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\StuckRects3' $settings = (Get-ItemProperty -Path $settingKey -Name Settings).Settings This code reads the value for the "Settings" property for the $settingskey key. However, this particular property is a REG_BINARY type. Here is where I get lost. Powershell represents binary as an array of integers, which is important, as the code which configures the settings I need performs a bitwise OR operation on the eighth element of that binary array, and then sets the property to this new value: $settings[8] = $settings[8] -bor 1 Set-ItemProperty -Path $settingKey -Name Settings -Value $settings On the other hand, autoit represents binary as a string, so I am trying to figure out how to perform the autoit equivalent of the powershell code I posted above. I already know that the number of elements in the powershell binary array is the same as the number returned by the BinaryLen function when passed the binary varient, so I am guessing I can use the "BinaryMid" function to access the byte that needs to be modified. I have already found that BitOR ( BinaryMid ( $setting, 9, 1 ), 1 ) returns the same value as $settings[8] -bor 1, so, assuming that that is all correct, my one question is: 1) Once the bitwise OR operation has modified the byte in question, how do I replace the byte stored in the $settings binary variant with the modified byte so I can save the value to the registry? This is what I have so far: $key = 'HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced' $settingKey = 'HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\StuckRects3' $setting = RegRead ( $settingKey, "Settings" ) $val = BitOR ( BinaryMid ( $setting, 9, 1 ), 1 ) Thanks in advance. Edited November 17, 2025 by MattHiggs
Developers Jos Posted November 17, 2025 Developers Posted November 17, 2025 Something like this (untested) ?: $key = 'HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced' $settingKey = 'HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\StuckRects3' $setting = RegRead($settingKey, "Settings") ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $setting = ' & $setting & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console ; Get Dec value of byte 9 and bitor with 1 $val = BitOR(Dec(BinaryMid($setting, 9, 1)), 1) ; replace the 9th bunary value in the string $setting = StringReplace($setting, 18, hex($val,2)) ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $setting = ' & $setting & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console ps: settings[8] is the 9th Hex2 value as the array is a 0 based array, meaning 0 is the first item, so 8 is the 9th item. SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past.
MattHiggs Posted November 17, 2025 Author Posted November 17, 2025 1 hour ago, Jos said: Something like this (untested) ?: $key = 'HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced' $settingKey = 'HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\StuckRects3' $setting = RegRead($settingKey, "Settings") ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $setting = ' & $setting & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console ; Get Dec value of byte 9 and bitor with 1 $val = BitOR(Dec(BinaryMid($setting, 9, 1)), 1) ; replace the 9th bunary value in the string $setting = StringReplace($setting, 18, hex($val,2)) ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $setting = ' & $setting & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console ps: settings[8] is the 9th Hex2 value as the array is a 0 based array, meaning 0 is the first item, so 8 is the 9th item. Thanks for your input. I will give it a shot.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now