Change binary registry: How to convert hex string to binary array

Home Forums Scripting Windows Script Host Change binary registry: How to convert hex string to binary array

This topic contains 5 replies, has 5 voices, and was last updated by Avatar Anonymous 9 years, 6 months ago.

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • Avatar
    huyenthu
    Member
    #149114

    Hi everyone,

    I want to use vbscript to change vnc pass for all client PC (by GPO)
    VNC password is binary value

    When I export registry, this value is:

    “Password”=hex:e2,9c,2a,e6,70,1b,ce,dd,95,58,52,eb,29,d3,f7,d2

    I found 1 vbscript to change VNC Password:

    —- – – – – – – – – – – – – – – – – – – – – – –
    Const HKEY_LOCAL_MACHINE = &H80000002
    Dim strComputer
    Dim objRegistry
    Dim strKeyPath
    Dim arrValues
    Dim strValueName
    strComputer = “.”
    Set objRegistry=GetObject(“winmgmts:{impersonationLevel=impersonate}!\” & _
    strComputer & “rootdefault:StdRegProv”)
    strKeyPath = “SOFTWARERealVNCWinVNC4”
    strValueName = “Password”
    arrValues = Array()
    objRegistry.SetBinaryValue HKEY_CURRENT_USER,strKeyPath,strValueName,arrValues
    – – – – – – – – – – – – – – – – – – – – – – – – – –

    How can I convert from hex string

    hex:e2,9c,2a,e6,70,1b,ce,dd,95,58,52,eb,29,d3,f7,d2

    to binary array to input in that vbscript?

    Avatar
    vonPryz
    Member
    #347452

    Re: Change binary registry: How to convert hex string to binary array

    huyenthu;204772 wrote:
    hex:e2,9c,2a,e6,70,1b,ce,dd,95,58,52,eb,29,d3,f7,d2

    to binary array to input in that vbscript?

    Try Array() or Split():

    Code:
    strRegKey = “[I][B]hex:e2,9c,2a,e6,70,1b,ce,dd,95,58,52,eb,29,d3,f7,d2″[/B][/I]
    strRegKey = Replace(strRegKey, “hex:”, “”) ‘ remove the hex: prefix

    ‘ Create an array out of the values, way 1
    arrRegKey = Array(strRegKey)

    ‘ Create an array out of the values, way 2
    arrRegKey = Split(strRegKey, “,”)

    -vP

    Avatar
    Ossian
    Moderator
    #181283

    Re: Change binary registry: How to convert hex string to binary array

    and for the hex to binary, a lookup table to convert each char (16 only) into the four bit values

    Avatar
    Anonymous
    #372308

    Re: Change binary registry: How to convert hex string to binary array

    Hi,

    Thanks for your solutions, however they didn’t solve my problem.

    Actually now I still not find the way how to change binary registry value by VBscript :-(

    Rems
    Rems
    Moderator
    #227718

    Re: Change binary registry: How to convert hex string to binary array

    You can use the vbs function CLng() to Convert Hexadecimal Numbers to Decimal.

    But you’ll have to use it on each item in the array of hex values separately! – so I’ve created the function DecimalNumbers() in the sample script.

    Const HKEY_CURRENT_USER = &H80000001
    Const HKEY_LOCAL_MACHINE = &H80000002

    Dim strComputer, objRegistry
    Dim strKeyPath, strValueName
    Dim strHexValues, arrHexValues, arrDecValues

    strComputer = “.”

    Set objRegistry=GetObject( _
    “winmgmts:{impersonationLevel=impersonate}!\” & _
    strComputer & “rootdefault:StdRegProv”)

    strKeyPath = “SOFTWARERealVNCWinVNC4”
    strValueName = “Password”
    strHexValues = “[COLOR=”Red”][B]hex:e2,9c,2a,e6,70,1b,ce,dd,95,58,52,eb,29,d3,f7,d2[/B][/COLOR]”

    arrHexValues = Split(Replace(strHexValues, “hex:”, “”), “,”)
    arrDecValues = DecimalNumbers(arrHexValues)

    objRegistry.SetBinaryValue [B]HKEY_LOCAL_MACHINE[/B], _
    strKeyPath, strValueName, arrDecValues

    Function DecimalNumbers(arrHex)
    Dim i, strDecValues
    For i = 0 to Ubound(arrHex)
    If isEmpty(strDecValues) Then
    strDecValues = CLng(“&H” & arrHex(i))
    Else
    strDecValues = strDecValues & “,” & CLng(“&H” & arrHex(i))
    End If
    next
    DecimalNumbers = split(strDecValues, “,”)
    End Function[/CODE]

    Rems[CODE]
    Const HKEY_CURRENT_USER = &H80000001
    Const HKEY_LOCAL_MACHINE = &H80000002

    Dim strComputer, objRegistry
    Dim strKeyPath, strValueName
    Dim strHexValues, arrHexValues, arrDecValues

    strComputer = “.”

    Set objRegistry=GetObject( _
    “winmgmts:{impersonationLevel=impersonate}!\” & _
    strComputer & “rootdefault:StdRegProv”)

    strKeyPath = “SOFTWARERealVNCWinVNC4”
    strValueName = “Password”
    strHexValues = “hex:e2,9c,2a,e6,70,1b,ce,dd,95,58,52,eb,29,d3,f7,d2

    arrHexValues = Split(Replace(strHexValues, “hex:”, “”), “,”)
    arrDecValues = DecimalNumbers(arrHexValues)

    objRegistry.SetBinaryValue HKEY_LOCAL_MACHINE, _
    strKeyPath, strValueName, arrDecValues

    Function DecimalNumbers(arrHex)
    Dim i, strDecValues
    For i = 0 to Ubound(arrHex)
    If isEmpty(strDecValues) Then
    strDecValues = CLng(“&H” & arrHex(i))
    Else
    strDecValues = strDecValues & “,” & CLng(“&H” & arrHex(i))
    End If
    next
    DecimalNumbers = split(strDecValues, “,”)
    End Function[/CODE]

    Rems

    Avatar
    Anonymous
    #372312

    Re: Change binary registry: How to convert hex string to binary array

    Thanks Rems,

    Your code works well.

    It is very useful for me :-)

Viewing 6 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic.