Sign in to follow this  
Followers 0

Registry Key Type Support

3 posts in this topic


I was wondering, is REG_BINARY registry type supported when using RegRead?

If not, when it will be supported?


Share this post

Link to post
Share on other sites

No it's not. I put it in as a request and people seem to want it but unfortunately unless you know how to code in C or C++ you will have to wait until somebody that does has the time to code it. But don't worry I think by the final release this will be in it. =)


Share this post

Link to post
Share on other sites

#3 ·  Posted (edited)

Here's a scripted version tested on Windows XP sp1:

It works by using regedit to export the regkey to a file.

(Actually, the resulting file is badly formatted if you look at it with a hex editor; consequently, the type tmp1 > tmp2 is required so FileReadLine will work.)

The regedit dump splits really long binary keys are split into lines using the "\" continutation character. This script has been modified to work for such long keys....

There may be bugs; Valik or Larry could probably suggest improvements.

; Example usage
$var = _RegReadBin("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Network", "Config")
MsgBox(4096,"Config", $var)

; Read a REG_BINARY value type from the registry
;   It uses the export command-line param of regedit
;   _RegReadBin ( "keyname", "valuename" ) 
;  Success:  Returns the requested registry value value.
;  Failure:  Returns "" and sets the @error flag
;              1 = Unable to open requested key
;             -1 = Unable to open requested value

Func _RegReadBin($keyName, $valueName) 

   Local $tmp0
   Local $tmp1
   Local $errorValue
   Local $returnValue

   $errorValue = 0
   $returnValue = ""

   $tmp0 = @TempDir & '\readBinZero.txt'
   $tmp1 = @TempDir & '\readBinOne.txt'

   _RunCmd('regedit /e ' & $tmp0 & ' ' & $keyName)
   _RunCmd('type "' & $tmp0 & '" > "' & $tmp1 & '"')

   $file = FileOpen($tmp1, 0)
   If $file = -1 Then ;Unable to open file, thus:
      $errorValue = -1;  Unable to open requested key

   Local $isFound
   $isFound =0

 ; Read in lines of text until the EOF is reached
   While $errorValue = 0
      $line = FileReadLine($file)
      If @error = -1 Then;Reached end-of-file, thus:
         $errorValue = 1 ;  Unable to open requested value
      $line = StringStripWS($line, 3)
      Local $pos
      If (Not $isFound) AND StringInStr($line, $valueName) Then
         $pos = StringInStr($line, "=hex:")
         $returnValue = StringTrimLeft($line, $pos + 4)
         $isFound = 1
      If $isFound AND StringInStr($line, "\") Then
         While StringInStr($line, "\")
            $line = StringStripWS( FileReadLine($file) , 3)
            $returnValue = $returnValue & @LF & $line
         $line = StringStripWS( FileReadLine($file) , 3)
         $returnValue = $returnValue & @LF & $line

   If $file <> -1 Then FileClose($file)
   Return $returnValue

; Helper function to run console commands
Func _RunCmd($command)
   Return RunWait(@ComSpec & ' /c ' & $command, "", @SW_HIDE)
Edited by CyberSlug

Use Mozilla | Take a look at My Disorganized AutoIt stuff | Very very old: AutoBuilder 11 Jan 2005 prototype I need to update my sig!

Share this post

Link to post
Share on other sites

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
Sign in to follow this  
Followers 0