Jump to content

Custom Registry Functions UDF


wraithdu
 Share

Recommended Posts

Apparently RegDeleteKeyEx is not available on 32-bit XP. I'm surprised this error hasn't been reported before. I'll have to look into the best way to fix it. For reference, the Ex functions are used to enable action on a specific 32 or 64 bit registry view on a 64-bit OS.

Link to comment
Share on other sites

Thanks, the move and delete functions work great on xp now

here is another issue(s) I have found with copy of multi reg sz.. -- I think I tracked it down to the _regread

1. Create a test mutli reg sz "hi" "whats" "up" on different lines,

autoit regread :

hi

whats

up

regread func: 0x68006900200000007700680061007400730000007500700000000000

if I do _regwrite of this value is shows up as this value

2. did autoit regwrite and _regwrite of the above autoit regread -- and _regwrite comes out slightly different

in regedit, it come out "hi whatsup" on one line

regexport: (your regexport work great )

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\test]

"testmsz"=hex(7):68,00,69,00,20,00,00,00,77,00,68,00,61,00,74,00,73,00,00,00,\

75,00,70,00,00,00,00,00

"autoit"=hex(7):68,00,69,00,20,00,00,00,77,00,68,00,61,00,74,00,73,00,00,00,75,\

00,70,00,00,00,00,00

"regfunc"=hex(7):68,00,69,00,20,00,0a,00,77,00,68,00,61,00,74,00,73,00,0a,00,\

75,00,70,00,00,00,00,00

in case you care here is the export of the copyvalue of the above testmsz

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\software\test]

"copy"=hex(7):30,00,78,00,36,00,38,00,30,00,30,00,36,00,39,00,30,00,30,00,32,\

00,30,00,30,00,30,00,30,00,30,00,30,00,30,00,37,00,37,00,30,00,30,00,36,00,\

38,00,30,00,30,00,36,00,31,00,30,00,30,00,37,00,34,00,30,00,30,00,37,00,33,\

00,30,00,30,00,30,00,30,00,30,00,30,00,37,00,35,00,30,00,30,00,37,00,30,00,\

30,00,30,00,30,00,30,00,30,00,30,00,30,00,30,00,30,00,30,00,00,00,00,00

Link to comment
Share on other sites

Bah, I hate MULTI_SZ. One problem is that _RegRead returns UTF16LE binary data and like an idiot in the CopyValue function I call _RegWrite directly, which expects string data. I'll fix this (and in other places).

Regarding your other test, don't mix native functions with UDF functions in this case. The returned and expected data types/formats are not necessarily compatible.

Link to comment
Share on other sites

Alright, I think I've fixed it. The Copy/Move functions will work properly now. I've also allowed _RegWrite to accept REG_MULTI_SZ input as either CRLF or LF delimited substrings as string data (as returned from AutoIt native RegRead), or as UDF internal type NULL delimited substrings as UTF16LE binary data.

Example data:

; string data
$d = "Hi" & @CRLF & "whats" & @CRLF & "up"
; binary data
$d = StringToBinary("Hi" & ChrW(0) & "whats" & ChrW(0) & "up", 2) ; note flag 2 for UTF16LE
Link to comment
Share on other sites

wraithdu

#include <_RegFunc.au3>
_RegExport(@ScriptDir&'_RegFunc - out.reg', 'HKEY_LOCAL_MACHINESOFTWAREMicrosoftWindowsCurrentVersionExplorerAutoplayHandlersHandlersImgBurnBDBurningOnArrival_BuildImage')

result:

Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINESOFTWAREMicrosoftWindowsCurrentVersionExplorerAutoplayHandlersHandlersImgBurnBDBurningOnArrival_BuildImage]
"DefaultIcon"=""C:Program FilesImgBurnImgBurn.exe",0"

should be so

Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINESOFTWAREMicrosoftWindowsCurrentVersionExplorerAutoplayHandlersHandlersImgBurnBDBurningOnArrival_BuildImage]
"DefaultIcon"=""C:Program FilesImgBurnImgBurn.exe",0"

"DefaultIcon"=""C:Program FilesImgBurnImgBurn.exe",0"

________________________________

#include <_RegFunc.au3>
_RegExport(@ScriptDir&'_RegFunc - out.reg', 'HKEY_LOCAL_MACHINESYSTEMControlSet001ControlArbitersReservedResources')

# 10
[HKEY_LOCAL_MACHINESYSTEMControlSet001ControlArbitersReservedResources]

nothing

________________________________

#include <_RegFunc.au3>
_RegExport(@ScriptDir&'_RegFunc - out.reg', 'HKEY_LOCAL_MACHINEHARDWARERESOURCEMAPHardware Abstraction LayerACPI 1.0 - APIC platform MP')

# 8
[HKEY_LOCAL_MACHINEHARDWARERESOURCEMAPHardware Abstraction LayerACPI 1.0 - APIC platform MP]

nothing

Edited by AZJIO
Link to comment
Share on other sites

wraithdu

I have full access. WinXP

I just compared the results with the function

Just I already had problems with some registry keys.

I was not able to export the HKEY_LOCAL_MACHINEHARDWARERESOURCEMAPPnP ManagerPnpManager, while regedit is exported correctly.

You like to try and break stuff huh?

No. This is a very responsible function, I only warned of the shortcomings. I once compared the results of the export of its function with the results regedit and therefore knew about the registry keys that cause problems.
Link to comment
Share on other sites

Don't take my breaking stuff comment seriously, I was just being sarcastic. I appreciate the bug reports.

That said, are you still having problems with the updated version? I just tried the key you mentioned

HKEY_LOCAL_MACHINEHARDWARERESOURCEMAPPnP ManagerPnpManager

and it exported identically to regedit. Now I'm on Win7 x64, so there could be a platform issue. Let me know.

Link to comment
Share on other sites

Thanks for all your hard work on this, it is a great UDF..

I tested on xp sp 3 32 bit and win 7 sp 1 64 bit and all the move/ copy/write functions work great..

a couple more issues -- tell me if you want me to stop finding stuff :)

minor issue:

msgbox(0,"", _regread("HKLM\software\test", "REG_MULTI_SZ") ) returns the binary data

The following may not be an issue, it could be working as design

on 64 bit (32 bit binary)

_regexport ($testfile, "HKLM\software\test")

correctly reads "HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\test"

however outputs

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\software\test]

If I import with 32 bit script, will import to Wow6432Node, however if I double click on the reg file it will import to "HKEY_LOCAL_MACHINE\SOFTWARE\test"

This time I have a possible, it seems to work on my limited testing, I am sure you will have a more elegant solution:

in _regexport -- after:

If Not _RegKeyExists($s_key) Then Return SetError(1, 0, 0)

If @OSArch = "x64" And Not @AutoItX64 Then
  Select
   Case StringInStr($s_key, "HKLM32\SOFTWARE")
    $s_key = StringReplace($s_key, "HKLM32\SOFTWARE", "HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node")
   Case StringInStr($s_key, "HKLM\SOFTWARE")
    $s_key = StringReplace($s_key, "HKLM\SOFTWARE", "HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node")
   Case StringInStr($s_key, "HKEY_LOCAL_MACHINE\SOFTWARE")
    $s_key = StringReplace($s_key, "HKEY_LOCAL_MACHINE\SOFTWARE", "HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node")
  Endselect
EndIf
Link to comment
Share on other sites

wraithdu

What if to make function of export with return to a variable, instead of to a file? To add parameter which has two values "First" and "Next". The first variant returns with a line with a line "Windows Registry Editor Version 5.00". The second variant without this line to attach to the first variant. There will be a flexibility, possibility to process the data before save to a file. And allows you to export some selected keys in the same file

Otherwise in a current kind it is enough to make "reg export"

for example

_RegExportToFile(@MyDocumentsDir&'_RegExport - Explorer.reg', 'HKEY_CLASSES_ROOT.avi')

$data=_RegExportToData('HKEY_CLASSES_ROOT.7z', 0) ; Start
$data&=_RegExportToData('HKEY_CLASSES_ROOT.wim', 1) ; Next
$file = FileOpen(@ScriptDir&'file.reg',2)
FileWrite($file, $data)
FileClose($file)


Func _RegExportToFile($Path, $Key)
$data=_RegExportToData($Key, 0) ; Start
$file = FileOpen($Path, 2)
FileWrite($file, $data)
FileClose($file)
EndFunc
Edited by AZJIO
Link to comment
Share on other sites

minor issue:

msgbox(0,"", _regread("HKLMsoftwaretest", "REG_MULTI_SZ") ) returns the binary data

This is actually by design and defined in the header. I'm on the fence about changing it to match AutoIt's behavior, even though _regwrite will accept AutoIt fomatted MULTI_SZ data. I'm assuming from your report that you would expect the return to match AutoIt's format?

The following may not be an issue, it could be working as design

on 64 bit (32 bit binary)

_regexport ($testfile, "HKLMsoftwaretest")

correctly reads "HKEY_LOCAL_MACHINESOFTWAREWow6432Nodetest"

however outputs

......

This is not by design however. You're right that the exported file should match platform and bitness. I'll look into it. Edited by wraithdu
Link to comment
Share on other sites

So I've updated it to change the return of MULTI_SZ data to be comparable to AutoIt's RegRead (except I've used CRLF instead of LF - no idea why AutoIt returns LF).

But I haven't changed the Wow6432Node stuff, and here's why... Look at this document:

http://msdn.microsoft.com/en-us/library/aa384253(v=vs.85).aspx

There are keys within redirected keys which ARE NOT redirected. And the list is huge. And behavior is different by platform as well! I don't feel like hardcoding all that shit. It would be easier I think to require a user to be more aware of the environment and use keys like 'HKLMSoftwareWow6432Node' instead of 'HKLM32Software'.

What do you think?

Edited by wraithdu
Link to comment
Share on other sites

Yea, that would be too much too code..

If someone is using this, I would hope they know what they are trying to accomplish

I do not know about dll calls, it is on my list of stuff to get more familiar with ... Could you do a dll call to find what actual key is being accessed after the redirect .. if there was such a call, you could set s_key with the output..

Link to comment
Share on other sites

Your suggestion only requires minor changes I think (omitting or including the file header), so it's something I can look at for sure.

Another vote for this. Being able to export several different registry keys into one file would be awesome...

Regarding the import of registry entries from a. reg file: I suppose we have to use the windows command "reg" invoked via ShellExecuteWait?

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...