Jump to content



Photo

Custom Registry Functions UDF


  • Please log in to reply
53 replies to this topic

#1 wraithdu

wraithdu

    I am less fun than a twisted ankle.

  • MVPs
  • 2,137 posts

Posted 30 April 2008 - 12:28 AM

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 to AutoIt's native RegRead function: CRLF delimited substrings. (AutoIt's RegRead actually returns LF delimited substrings.)

Update 1/29/12:
v2.0.5
Added more supported formats to the Export function and fixed infinite loop errors. REG_LINK remains unsupported.
v2.0.4
Fixed some REG_MULTI_SZ issues in Write/Copy/Move functions. Re-read the _RegWrite header notes for the pertinent information. Thanks again step887 for reporting.

Update 1/28/12:
v2.0.3
Do not use RegDeleteKeyEx on 32-bit OS's, it is not needed (and does not exist on XP 32-bit and lower, or lower than Server 2003 SP1). Thanks step887 for reporting the error!

Update 12/2/10:
v2.0.2
Fixed wrong @error return from _RegRead which would cause _RegValueExists to incorrectly return Success.

Update 5/25/10:
Ok, huge overhaul.

Added:
- Function documentation!
- Improved _RegRead and _RegWrite to better handle data. Specifically, REG_MULTI_SZ data types are correctly read / exported if the data was incorrectly written to the registry by another application. And the data is correctly written even if it was supplied to the function with incorrect termination. Because of the unusual format of this data type, it is returned from _RegRead as binary data.
- _RegRead / _RegWrite support all known registry value data types (in at a least a limited way). For uncommon types, the values are read / written as binary data.
- Better error checking and reporting, especially before any delete operations.
- x64 Platform: Support for directly reading the 32-bit and 64-bit registry views from both 32-bit and 64-bit scripts.
- All operations are now done via custom registry functions. I didn't want to go all the way, but AutoIt doesn't support a root key like HKLM32 to force reading the 32-bit registry on the x64 platform from a native 64-bit script. Once I decided to introduce that capability in some of the higher level functions, I had to rewrite all the low level functions as well.
- _RegExport function to recursively export a key or a single value to a MS compatible REG file.
- Other undocumented helper functions that could be pilfered for nefarious usage.

There might be some more minor things that I've forgotten. I've tested this pretty well, but please report any bugs or problems.

Update 4/16/2010:
Added the latest version of this UDF. It includes some custom _RegWrite / _RegRead functions as well. The _RegWrite function allows you to set the REG_OPTION_VOLATILE flag on a registry key. Example at the bottom.

I needed this for a script, and didn't necessarily like big_daddy's solution. Here's a recursive registry copy/move function. I tested it and it seems to work perfectly (knock on wood). It could probably use some more error catching, so suggestions are welcome.

Attached Files


Edited by wraithdu, 02 February 2012 - 02:51 PM.

  • Mat likes this





#2 wraithdu

wraithdu

    I am less fun than a twisted ankle.

  • MVPs
  • 2,137 posts

Posted 30 April 2008 - 12:47 AM

Threw in _RegCopyValue / _RegMoveValue for good measure.

_RegCopyValue / _RegMoveValue

** above

Edited by wraithdu, 16 April 2010 - 05:04 PM.


#3 wraithdu

wraithdu

    I am less fun than a twisted ankle.

  • MVPs
  • 2,137 posts

Posted 30 April 2008 - 03:44 AM

Seems I needed more -

_RegKeyExists / _RegValueExists / _RegKeyEmpty

** above

Edited by wraithdu, 16 April 2010 - 05:04 PM.


#4 WeMartiansAreFriendly

WeMartiansAreFriendly

    Where's the kaboom?

  • Active Members
  • PipPipPipPipPipPip
  • 1,245 posts

Posted 30 April 2008 - 04:33 AM

Thanks for sharing. I wrote similar functions, but not quite as elegant.
Posted ImageDon't bother, It's inside your monitor!------GUISetOnEvent should behave more like HotKeySet()

#5 wraithdu

wraithdu

    I am less fun than a twisted ankle.

  • MVPs
  • 2,137 posts

Posted 05 May 2008 - 04:20 PM

Update, properly declare variables in functions. Caught myself in recursion hell cause of this...

** above

search terms: regmovekey regcopykey moveregkey copyregkey movekey copykey reg registry move copy key

Edited by wraithdu, 16 April 2010 - 05:04 PM.


#6 wraithdu

wraithdu

    I am less fun than a twisted ankle.

  • MVPs
  • 2,137 posts

Posted 01 July 2008 - 04:46 AM

Small update, added _RegSubkeySearch() which searches keys for the searchterm and returns the key index, or 0 if not found.

Mode:
0 = substring search
1 = search from beginning of key name

Case sense:
0 = case insensitive
1 = case sensitive

So defaults would be a case insensitive substring search.

Edited by wraithdu, 01 July 2008 - 04:46 AM.


#7 dmoniac

dmoniac

    Seeker

  • Active Members
  • 21 posts

Posted 04 July 2008 - 09:17 AM

I take it, so good.

#8 mplsmark

mplsmark

    Seeker

  • Normal Members
  • 1 posts

Posted 30 April 2009 - 03:06 PM

Just put this to use, thanks for posting.

#9 wraithdu

wraithdu

    I am less fun than a twisted ankle.

  • MVPs
  • 2,137 posts

Posted 16 April 2010 - 05:05 PM

Updated.

#10 wraithdu

wraithdu

    I am less fun than a twisted ankle.

  • MVPs
  • 2,137 posts

Posted 26 May 2010 - 04:52 AM

Major update. Please report any problems.

#11 asdf8

asdf8

    Wayfarer

  • Active Members
  • Pip
  • 67 posts

Posted 26 May 2010 - 06:42 AM

wraithdu
some keys are incorrectly exported:

_RegExport('example.reg', 'HKEY_CLASSES_ROOT\.doc')
Windows Registry Editor Version 5.00 [HKEY_CLASSES_ROOT\.doc] @="Word.document.8" "Content Type"="application/msword" [HKEY_CLASSES_ROOT\.doc\OpenWithList] [HKEY_CLASSES_ROOT\.doc\OpenWithList\WordPad.exe] @=""



regedit
Plain Text         
Windows Registry Editor Version 5.00 [HKEY_CLASSES_ROOT\.doc] @="Word.document.8" "Content Type"="application/msword" [HKEY_CLASSES_ROOT\.doc\OpenWithList] [HKEY_CLASSES_ROOT\.doc\OpenWithList\WordPad.exe] @="" [HKEY_CLASSES_ROOT\.doc\PersistentHandler] @="{98de59a0-d175-11cd-a7bd-00006b827d94}" [HKEY_CLASSES_ROOT\.doc\ShellNew] [HKEY_CLASSES_ROOT\.doc\Word.document.6] [HKEY_CLASSES_ROOT\.doc\Word.document.6\ShellNew] "FileName"="winword.doc" [HKEY_CLASSES_ROOT\.doc\Word.document.8] [HKEY_CLASSES_ROOT\.doc\Word.document.8\ShellNew] "FileName"="winword8.doc" [HKEY_CLASSES_ROOT\.doc\WordDocument] [HKEY_CLASSES_ROOT\.doc\WordDocument\ShellNew] "FileName"="winword2.doc" [HKEY_CLASSES_ROOT\.doc\WordPad.document.1] [HKEY_CLASSES_ROOT\.doc\WordPad.document.1\ShellNew] "NullFile"=""


#12 wraithdu

wraithdu

    I am less fun than a twisted ankle.

  • MVPs
  • 2,137 posts

Posted 26 May 2010 - 03:06 PM

Thanks, looking into it.

#13 wraithdu

wraithdu

    I am less fun than a twisted ankle.

  • MVPs
  • 2,137 posts

Posted 26 May 2010 - 03:33 PM

Ok, it's fixed. It was an Access Denied error when enumerating the keys... which makes no sense to me. As a general rule, I try open files / keys / whatever with the minimum required access rights. Apparently MSDN wasn't entirely truthful. I've updated everything to use either KEY_READ or KEY_WRITE, which should be minimal enough not to cause issues, yet provide all the normally required access rights.

#14 MasterChief

MasterChief

    Seeker

  • Active Members
  • 6 posts

Posted 26 May 2010 - 03:52 PM

Could you possibly add some way to edit permissions within a script. This would help me so much seeing as I need to write to the registry, but I need that value to be read only access to all users. Thanks

#15 wraithdu

wraithdu

    I am less fun than a twisted ankle.

  • MVPs
  • 2,137 posts

Posted 26 May 2010 - 04:04 PM

Look into the app SetACL, and script that. I have no idea what is required to set / change registry key / value permissions at this moment.

#16 KaFu

KaFu

    Hey, it's just me, KhaFoo...

  • MVPs
  • 3,164 posts

Posted 26 May 2010 - 04:53 PM

This looks really nice m8 :mellow:, thanks a lot, I'll take a deeper look :P...

#17 JFX

JFX

    Polymath

  • Active Members
  • PipPipPipPip
  • 206 posts

Posted 01 November 2010 - 05:03 PM

Thanks a lot, very good :graduated:

How about adding support for creation of symbolic links like Regln have?

#18 Fire

Fire

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 362 posts

Posted 05 November 2010 - 03:58 PM

Thx so much wraithdu for this GREAT UDF!
It solved my problem when reading REG_QWORD(11) types values from regedit!
+5 stars from me!
Thank you!

#19 wraithdu

wraithdu

    I am less fun than a twisted ankle.

  • MVPs
  • 2,137 posts

Posted 02 December 2010 - 07:07 PM

Dang, found a small bug today. See first post.

#20 step887

step887

    Seeker

  • Active Members
  • 42 posts

Posted 26 January 2012 - 05:35 PM

This is great work, however, I think I may have found an error,
I started off trying to use move key and it was failing
The copy works,, found out the delete was not

it works fine on my win 7 64 bit (not compiled)
when i copy to VM of xp sp3 32 bit, it does not work


$err = _RegWrite("HKEY_LOCAL_MACHINE\Software\test")
MsgBox(0,@extended, @error & @CRLF & $err)

$err = _RegKeyExists("HKEY_LOCAL_MACHINE\Software\test")
MsgBox(0,@extended, @error & @CRLF & $err)

$err = _RegDelete("HKEY_LOCAL_MACHINE\Software\test")
MsgBox(0,@extended, @error & @CRLF & $err)



return = 0 -- Failure - 0 and sets @error
@error = 3 --- Failed to delete key / value (@extended contains RegDelete* return value)
@extended = 0 ---Returns 0 if the key/value does not exist

everything else seems to work. (ie regwrite, regkeyexist)

I am not smart enough to figure out the dllcall




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users