Jump to content

Recommended Posts

Posted (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 by MattHiggs
  • Developers
Posted

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.
  :)

Posted
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.

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...