Announcement

Collapse
No announcement yet.

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

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

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

    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:{impersonationLeve l=impersonate}!\\" & _
    strComputer & "\root\default:StdRegProv")
    strKeyPath = "SOFTWARE\RealVNC\WinVNC4"
    strValueName = "Password"
    arrValues = Array()
    objRegistry.SetBinaryValue HKEY_CURRENT_USER,strKeyPath,strValueName,arrValue s
    - - - - - - - - - - - - - - - - - - - - - - - - - -

    How can I convert from hex string

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

    to binary array to input in that vbscript?

  • huyenthu
    replied
    Re: Change binary registry: How to convert hex string to binary array

    Thanks Rems,

    Your code works well.

    It is very useful for me

    Leave a comment:


  • Rems
    replied
    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.

    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 & "\root\default:StdRegProv")
    
    strKeyPath = "SOFTWARE\RealVNC\WinVNC4"
    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
    \Rems

    Leave a comment:


  • huyenthu
    replied
    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

    Leave a comment:


  • Ossian
    replied
    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

    Leave a comment:


  • vonPryz
    replied
    Re: Change binary registry: How to convert hex string to binary array

    Originally posted by huyenthu View Post
    hex:e2,9c,2a,e6,70,1b,ce,dd,95,58,52,eb,29,d3,f7,d 2

    to binary array to input in that vbscript?
    Try Array() or Split():

    Code:
    strRegKey = "hex:e2,9c,2a,e6,70,1b,ce,dd,95,58,52,eb,29,d3,f7,d2"
    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

    Leave a comment:

Working...
X