Jump to content

Custom Registry Functions UDF

Recommended Posts

  • Replies 74
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Popular Posts

Update 2/2/12: v2.0.7 Fix _RegRead returns string data for _RegExport. Update 1/30/12: v2.0.6 - SCRIPT BREAKING Change _RegRead treatment of REG_MULTI_SZ data. Data is returned in a comparable format

nothing. 2 years and nothing. can you believe that !. But I am of my word. If a "test.au3" pops up, I'll recreate the setup I offered two years ago, and sure as heck I'll get it done, or help me

Got the UDF. Nice looking code. Looking back, it makes my coding look ugly Still no test.au3 in the package but by now, you know the code is good. No need for testing. As far as getting ... "dimi


Thanks for update looks perfect now.

RegistryViewer with use _RegFunc.au3


Icon index changed in win7, unsure about vista:

IF @OSBuild < 5000 Then
_GUIImageList_AddIcon($hImage, @WindowsDir&'\regedit.exe', 7)
_GUIImageList_AddIcon($hImage, @WindowsDir&'\regedit.exe', 8)
_GUIImageList_AddIcon($hImage, @WindowsDir&'\regedit.exe', 3)
_GUIImageList_AddIcon($hImage, @WindowsDir&'\regedit.exe', 4)
Link to post
Share on other sites

RegistryViewer with use _RegFunc.au3

That is awesome...

wraithdu, I found another issue .... I think you may end up hating me...... ;)

On win 7 64 bit (and 2008 according to the link below) _regread on HKEY_CLASSES_ROOT64CLSID is not finding anything.. @error is 1 -- invalid root key..


Everything else under ROOT seems ok with HKEY_CLASSES_ROOT


HKEY_CLASSES_ROOT is a merged view of HKEY_LOCAL_MACHINESOFTWAREClasses and HKEY_CURRENT_USERSOFTWAREClasses. Redirected keys in these registry paths are effectively redirected for HKEY_CLASSES_ROOT also. This is also true for reflected keys on systems that support them.

I can read correctly if I am going under "HKEY_LOCAL_MACHINE64SOFTWAREClassesCLSID" and since it reflects to ROOT, i guess that is ok :)

Edited by step887
Link to post
Share on other sites


JFX is correct. I'm sure I left that out for a reason, however I can add it in with the next update... buyer beware. If you want to add in JFX's fix for now, go ahead, but also add the HKCR32 spec.

Edited by wraithdu
Link to post
Share on other sites
  • 2 months later...


Been using this all this time and it is solid. Found another issue/judgement call..

_regkeyexists and _regvalueexists was returning 0 if the registry key was there, but there was a permission issue.

_regread is returning @error = 2 - Failed to open source key (@extended contains RegOpenKeyExW return value) @extended = 5 (ERROR_ACCESS_DENIED)

I modified both functions to:

_RegRead($s_key, "") ; try to read default value
$error = @error
$extended = @extended
If $error = 2 And $extended = 5 Then Return SetError(0, $extended, 2)
Switch $error
  Case 1, 2
   ; invalid root key | failed to open key
   Return SetError($error, $extended, 0)
  Case Else
   ; key exists
   Return SetError(0, 0, 1)

The only reason I used $error and $extended was there was an issue with the script when it was Obfuscated and I used @error and @extended.

Edited by step887
Link to post
Share on other sites
  • 1 month later...

I tried to make himself - _RegExportToData

If (Not IsArray($ret)) Or ($ret[0] <> 0) Then
        If IsArray($ret) Then
            Return SetError(3, $ret[0], 0)
            Return SetError(3, 0, 0)

replace it

If IsArray($ret) Then
        If $ret[0] <> 0 Then Return SetError(3, $ret[0], 0)
        Return SetError(3, 0, 0)
Edited by AZJIO
Link to post
Share on other sites
  • 1 year later...

it seems RegCopyValue() and _RegWrite() errorour on while working ok on

i'm trying to copy default reg value from one key to another with:

_RegCopyValue( $copy_From, "", $copy_To, "" )

but get @error = 3 - Failed to write destination value (@extended contains _RegWrite error code)

@extended = 2 - Failed to open / create destination key (@extended contains RegCreateKeyExW return value)

_RegWrite error code @extended = 5 --> RegOpenKeyEx access denied (error 5)

reproduce code: (it's coping windows default sound scheme to current)

    Switch @OSArch
        Case "X64"
            $OSKey = "64"
        Case "X86"
            $OSKey = ""

                      RegWrite("HKEY_CURRENT_USER" & $OSKey & "\AppEvents\Schemes", '', "REG_SZ", '.default')
            $i = 0
            While 1
                $i += 1
                $subKEY_1 = RegEnumKey("HKEY_CURRENT_USER" & $OSKey & "\AppEvents\Schemes\Apps", $i)
                If @error <> 0 Then ExitLoop 1
                $j = 0
                While 1
                    $j += 1
                    $subKEY_2 = RegEnumKey("HKEY_CURRENT_USER" & $OSKey & "\AppEvents\Schemes\Apps\" & $subKEY_1, $j)
                    If @error <> 0 Then ExitLoop 1
                    $copy_From = "HKEY_CURRENT_USER" & $OSKey & "\AppEvents\Schemes\Apps\" & $subKEY_1 & "\" & $subKEY_2 & "\.Default"
                    $copy_To = "HKEY_CURRENT_USER" & $OSKey & "\AppEvents\Schemes\Apps\" & $subKEY_1 & "\" & $subKEY_2 & "\.Current"
                    _RegCopyValue( $copy_From, "", $copy_To, "" )
                    ConsoleWrite("@error = "&@error&"   @extended = "&@extended&@crlf)
Edited by Iczer
Link to post
Share on other sites

I do not think something can block regwrite so selectively since i'm on XP, i'm don't have AV, firewall have same permissions (verified) for AutoIt3.exe from both and and most impotant (!) if i replace this:

_RegCopyValue( $copy_From, "", $copy_To, "" )

with this:

$value = RegRead($copy_From,"")
$type = @extended
Switch $type
    Case $REG_SZ
        $type = "REG_SZ"
        $type = "REG_EXPAND_SZ"
RegWrite($copy_To, "", $type, $value)

it works perfectly in both and

So if _RegCopyValue works in and not in, it have to be UDF or realisation of dllcall in i think.

Link to post
Share on other sites
  • 1 month later...


the function regexport doesn't work in my computer.

I create a new using the export from windows :

Func regExport($file, $key)

    Local $tempFile = @TempDir & "\regExportFunction.txt"
    Local $arrayFile, $Return

    if not FileExists($file) Then
        $Return = FileWrite($file, "Windows Registry Editor Version 5.00" &  @CRLF & @CRLF)
        if $Return = 0 Then Return SetError(1,2,0)

    RunWait(@ComSpec & " /c " & 'reg export "' & $key & '" "' & $tempFile & '"', "", @SW_HIDE )
    if @error Then Return SetError(@error,0,0)

    $arrayFile = FileReadToArray($tempFile)
    if @error then
        FileWrite($file, "; [" & $key & "]" & @CRLF & "; Key does not exist" & @CRLF & @CRLF)
        Return 1

    $Return = FileDelete($tempFile)
    if $Return = 0 Then Return SetError(1,1,0)

    For $i = 2 to Ubound($arrayFile) - 1
        FileWrite($file, $arrayFile[$i] &  @CRLF)
        if $Return = 0 Then Return SetError(1,3,0)

    Return 1

Link to post
Share on other sites
  • 1 month later...

Just tried running it in the latest AutoIt ( and got (since it's already defined in constants.au3 which the script includes):

Global Const $REG_QWORD = 11
_RegFunc.au3"(20,29) : error: $REG_QWORD previously declared as a 'Const'.
Edited by LWC
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
  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...