Yashied Posted October 8, 2010 Posted October 8, 2010 (edited) A small but fast function to export the data from the registry to a file or variable. _RegExportEx() does not use regedit.exe and any temporary files, only AutoIt. Also required WinAPIEx UDF to work this function. I hope this will be useful to someone. expandcollapse popup#Include <APIConstants.au3> #Include <WinAPIEx.au3> $sReg = _RegExportEx('HKEY_CLASSES_ROOT\AutoIt3Script') If @error Then ConsoleWrite(_WinAPI_GetErrorMessage(@extended) & @CR) Else ConsoleWrite($sReg & @CR) EndIf Func _RegExportEx($sKey, $sFile = '', $fAssurance = 0) Local $aData = StringSplit(StringUpper($sKey), '\', 2) Local $tData, $hRoot, $sRoot, $sReg = '' Local $Error = 1 If Not IsArray($aData) Then Return SetError(1, 0, '') EndIf Switch $aData[0] Case 'HKEY_CLASSES_ROOT', 'HKEY_CURRENT_USER', 'HKEY_LOCAL_MACHINE', 'HKEY_USERS', 'HKEY_CURRENT_CONFIG' $sRoot = $aData[0] Case 'HKCR' $sRoot = 'HKEY_CLASSES_ROOT' Case 'HKCU' $sRoot = 'HKEY_CURRENT_USER' Case 'HKLM' $sRoot = 'HKEY_LOCAL_MACHINE' Case 'HKU' $sRoot = 'HKEY_USERS' Case 'HKCC' $sRoot = 'HKEY_CURRENT_CONFIG' Case Else Return SetError(1, 0, '') EndSwitch $sKey = StringTrimLeft($sKey, StringLen($aData[0]) + 1) Do $hRoot = _WinAPI_RegOpenKey(Eval($sRoot), $sKey, BitOR($KEY_ENUMERATE_SUB_KEYS, $KEY_QUERY_VALUE)) If @error Then ExitLoop EndIf $tData = DllStructCreate('byte[1048576]') If Not _RegEnumProc($hRoot, StringRegExpReplace($sRoot & '\' & $sKey, '\\*\Z', ''), $fAssurance, $sReg, $tData) Then ExitLoop EndIf $Error = 0 Until 1 If $Error Then Switch @extended Case 0 $Error = -1 Case Else $Error = @extended EndSwitch EndIf If $hRoot Then _WinAPI_RegCloseKey($hRoot) EndIf If $Error Then Return SetError(2, $Error, '') EndIf If $sFile Then $hFile = FileOpen($sFile, 2 + 32) If $hFile = -1 Then Return SetError(3, 0, '') EndIf If Not FileWrite($hFile, 'Windows Registry Editor Version 5.00' & @CRLF & @CRLF & $sReg) Then $Error = 1 EndIf FileClose($hFile) If $Error Then Return SetError(3, 0, '') EndIf Return 1 EndIf Return $sReg EndFunc ;==>_RegExportEx Func _RegEnumProc($hRoot, $sRoot, $fAssurance, ByRef $sData, ByRef $tData, $sParam = 0) Local $hKey, $sKey, $sVal, $Pos, $Size, $Type Local $pData = DllStructGetPtr($tData) Local $Count = 0, $Error = 0 If $sParam Then $sData &= @CRLF & '[' & $sRoot & '\' & $sParam & ']' & @CRLF Else $sData = '[' & $sRoot & ']' & @CRLF EndIf While 1 $sVal = _WinAPI_RegEnumValue($hRoot, $Count) If @error Then Switch @extended Case 259 ; ERROR_NO_MORE_ITEMS ExitLoop Case Else Return SetError(1, @extended, 0) EndSwitch EndIf $Size = _WinAPI_RegQueryValue($hRoot, $sVal, $tData) If @error Then Return SetError(1, @extended, 0) EndIf $Type = @extended If $sVal Then $sVal = '"' & StringReplace(StringReplace($sVal, '\', '\\'), '"', '\"') & '"=' Else $sVal = '@=' EndIf If Not $Size Then Switch $Type Case 1 ; REG_SZ $sVal &= '""' Case Else Switch $Type Case 3 ; REG_BINARY $sVal &= 'hex:' Case Else $sVal &= 'hex(' & StringLower(Hex($Type, 1)) & '):' EndSwitch EndSwitch Else Switch $Type Case 1 ; REG_SZ $sVal &= '"' & StringReplace(StringReplace(DllStructGetData(DllStructCreate('wchar[' & $Size & ']', $pData), 1), '\', '\\'), '"', '\"') & '"' Case 4 ; REG_DWORD $sVal &= 'dword:' & StringLower(Hex(Number(DllStructGetData(DllStructCreate('dword', $pData), 1)))) Case Else Switch $Type Case 3 ; REG_BINARY $sVal &= 'hex:' Case Else $sVal &= 'hex(' & StringLower(Hex($Type, 1)) & '):' EndSwitch $sVal &= StringTrimRight(StringRegExpReplace(StringLower(StringTrimLeft(DllStructGetData(DllStructCreate('byte[' & $Size & ']', $pData), 1), 2)), '(.{2})', '\1,'), 1) $Pos = StringInStr($sVal, ',', 0, 1, 77) If $Pos Then $sVal = StringLeft($sVal, $Pos) & '\' & @CRLF & ' ' & StringRegExpReplace(StringTrimLeft($sVal, $Pos), '(.{75})', '\1\\' & @CRLF & ' ') EndIf EndSwitch EndIf $sData &= $sVal & @CRLF $Count += 1 WEnd $Count = 0 While 1 $sKey = _WinAPI_RegEnumKey($hRoot, $Count) If @error Then Switch @extended Case 259 ; ERROR_NO_MORE_ITEMS ExitLoop Case Else Return SetError(1, @extended, 0) EndSwitch EndIf $hKey = _WinAPI_RegOpenKey($hRoot, $sKey, BitOR($KEY_ENUMERATE_SUB_KEYS, $KEY_QUERY_VALUE)) If @error Then If $fAssurance Then Return SetError(1, @extended, 0) EndIf Else If $sParam Then _RegEnumProc($hKey, $sRoot, $fAssurance, $sData, $tData, $sParam & '\' & $sKey) Else _RegEnumProc($hKey, $sRoot, $fAssurance, $sData, $tData, $sKey) EndIf If @error Then Switch @extended Case 0 $Error = -1 Case Else $Error = @extended EndSwitch EndIf EndIf If $hKey Then _WinAPI_RegCloseKey($hKey) EndIf $Count += 1 If $Error Then ExitLoop EndIf WEnd If $Error Then Return SetError(1, $Error, 0) Else Return 1 EndIf EndFunc ;==>_RegEnumProc Edited December 22, 2013 by Yashied My UDFs: iKey | FTP Uploader | Battery Checker | Boot Manager | Font Viewer | UDF Keyword Manager | Run Dialog Replacement | USBProtect | 3D Axis | Calculator | Sleep | iSwitcher | TM | NetHelper | File Types Manager | Control Viewer | SynFolders | DLL Helper Animated Tray Icons UDF Library | Hotkeys UDF Library | Hotkeys Input Control UDF Library | Caret Shape UDF Library | Context Help UDF Library | Most Recently Used List UDF Library | Icons UDF Library | FTP UDF Library | Script Communications UDF Library | Color Chooser UDF Library | Color Picker Control UDF Library | IPHelper (Vista/7) UDF Library | WinAPI Extended UDF Library | WinAPIVhd UDF Library | Icon Chooser UDF Library | Copy UDF Library | Restart UDF Library | Event Log UDF Library | NotifyBox UDF Library | Pop-up Windows UDF Library | TVExplorer UDF Library | GuiHotKey UDF Library | GuiSysLink UDF Library | Package UDF Library | Skin UDF Library | AITray UDF Library | RDC UDF Library Appropriate path | Button text color | Gaussian random numbers | Header's styles (Vista/7) | ICON resource enumeration | Menu & INI | Tabbed string size | Tab's skin | Pop-up circular menu | Progress Bar without animation (Vista/7) | Registry export | Registry path jumping | Unique hardware ID | Windows alignment More...
wraithdu Posted October 8, 2010 Posted October 8, 2010 Have you looked at my export function as part of my _RegFunc UDF? I haven't looked through yours completely to compare functionality...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now