' ' Editor: tlviewer@yahoo.com ' script: RegObj8209.vbs ' Description: RegObj reads and writes 8209 arrays for binary regtypes ' keywords: byte 8209 midb html array ' Date : 02/02/02 ' Q250344 - SAMPLE: ARRAYCONVERT.EXE Variant Conversion Functions ' http://support.microsoft.com/support/kb/articles/Q250/3/44.ASP ' ' Constants for Paul stBinString = 1 stHexString = 2 strHex = "112233441122334411223344" ' 1st method: KB sample referenced above in header 'Set cnvt = CreateObject("ADs.ArrayConvert") 'ads.dll 'binArray = cnvt.CvHexStr2vOctetStr(strHex) ' 2nd method: use function by Paul Randall binArray = StringTo8209( strHex, stHexString) ' echo vartype: is it an array? WScript.echo VarType( binArray ), ubound( binArray ) for nJ = 1 to Ubound( binArray) sOut = sOut & hex(ascb(midb(binArray, nJ,1 ))) & vbCrLf next WScript.echo sOut ' write to registry as Binary ''''''''''''''''''''''''''''''' strKey = "\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows Script Host\MyJunk" set objRegistry = CreateObject("RegObj.Registry") set objRegKey = objRegistry.RegKeyFromString(strKey) oldcnt =objRegKey.Values.count ' uncomment below to write the binArray to registry 'objRegKey.Values.Add "test", (binArray), 3 WScript.echo oldcnt, objRegKey.Values.count ' helper functions ''''''''''''''''''''' Function StringTo8209(strInput, iType) ' Paul Randall, October, 2002 'Create an ADO stream object. 'Set the stream type to 2; this will allow writing the data to the ' stream in text mode by passing it plain ASCII strings. 'BUT - change the characer set to x-ansi, also known as windows-1252 ' so that all 256 character codes are unchanged when read back in ' binary mode. Many other character sets do strange transformations. set stream = createobject("adodb.stream") stream.type = 2 stream.charset = "x-ansi" stream.open 'Depending on the iType value, write the string or byte-equivalents of ' the combined nibble-pairs to the stream, in text mode. if iType = stBinString then stream.writetext strInput, 0 elseif iType = stHexString then if (len(strInput) mod 2) <> 0 then err.raise vbObjectError + 1025, "StringTo8209", "Not a valid hex string" wscript.quit(vbObjectError + 1025) end if for n = 1 to len(strInput) -1 step 2 stream.writetext chr("&h" & mid(strInput,n,2)), 0 next else err.raise vbObjectError + 1026, "StringTo8209", _ "The second parameter to " & _ "Function StringTo8209(strInput, iType)" _ & vbcrlf & "must be either 1 for any char, or 2 for Hex chars." _ & vbcrlf & "You passed: " & iType & vbcrlf & "Quitting" wscript.quit end if 'Change the stream type to binary, so we can read a byte-array, ' and set the stream position to zero so we can read all the bytes. 'Note that the stream position must be zero before the stream type ' is changed, or an error occurs on changing stream type. Contents ' are not lost when changing stream.type. stream.position = 0 stream.type = 1 StringTo8209 = stream.read stream.close set stream = nothing end function