And as a function with error checking...
Code:
;*************************************************************************
; Script Name: Learning Round 2
; Author: Gargoyle
; Date: 9/25/2006
; Description: Change a binary string in the registry
;*************************************************************************
;Error Codes
; 0 = Change has been made
; 3 = Change String to long
; 4 = Change String not in range (0 - f)
; 5 = Unable to read Value
; 6 = Unable to write value
; 7 = Invalid Position
; Required values
; $Key = The Registry key to read
; $Entry = The Registry entry to read
; $Position = Which Binary position do you want to change
; $Changeto = The value to change to
Dim $SO
;Script Options
$SO=SETOPTION("Explicit", "ON")
$SO=SETOPTION("NoMacrosInStrings", "ON")
$SO=SETOPTION("NoVarsInStrings", "ON")
$SO=SETOPTION("WrapAtEOL", "ON")
If NOT @LOGONMODE
Break On
EndIf
ChangeBinary("HKCU\Software\KiXtart-Learning","Round02",3,"bc")
Function ChangeBinary($Key,$Entry,$Position,$ChangeTo)
Dim $ValRead,$Count,$Element,$valarray[],$ValWrite,$ValCheck[],$
$ValCheck = "0","1","2","3","4","5","6","7","8","9","a","b","c","d","e","f"
;Check to make sure the ChangeTo is acceptable
If Len($ChangeTo) > 2
Exit 3
EndIf
For $ = 1 to 2
If Ascan($ValCheck,SubStr($Changeto,$,1)) = -1
Exit 4
EndIf
Next
; For use in creating an array to allow for changes to said array
$Element = 0
; Read in the Value we want to work with
$ValRead = ReadValue($Key, $Entry3D"#000000" size=2>)
If @Error = 0
; Build an array with each element = to a binary group
For $Count = 1 to Len($ValRead) step 2
redim preserve $Valarray[$Element]
$ValArray[$Element] = SubStr($ValRead,$Count,2)
$Element = $Element + 1
Next
;Now we can change the element we want
If $Position > Ubound($Valarray)
Exit 7
Else
$Valarray[($Position - 1)] = $ChangeTo
EndIf
;And now to put it all back together so that we can write it
For $Count = 0 to Ubound($Valarray)
$ValWrite = $Valwrite + $ValArray[$Count]
Next
;Finally we write it back to the registry
If Writevalue($Key,$Entry,$ValWrite,"Reg_Binary") = 0
Else
Exit 6
EndIf
Else
Exit 5
EndIf
EndFunction
? @error