views:

65

answers:

2

I have been trying to find a way to "defragment" the registry on my Windows machine. Firstly, does this make sense? Any benefits in doing this? (Not much love on superuser.com) Secondly, I am looking for a way to rewrite the registry using C/C++ with Windows API. Is there a way to read the registry and write it to a new file getting rid of unused bytes along the way? (I might have to write the new file and then boot into another OS/disk before I can overwrite the original... but I am willing to take that risk.)

A: 

Reading the values should be possible.

But I've never seen any spec for how the registry files are written to disk, and unless you could find one you'd have to reverse engineer those files in your OS (might be differences between XP and 7 etc). Then you have to remember that the registry isn't just one file, it's multiple files and some of them belongs to certain users and I think they use SIDs rather than user names so even if you move them to a new computer, you have to be sure it's the same OS version with the same users with the same SIDs set up on it.

All this for little or no gain so I'd agree with the superuser users that it wouldn't make sense.

ho1
+2  A: 

Microsoft's PageDefrag does exactly this, as it states on its page "PageDefrag uses the standard file defragmentation APIs to defragment the files."

(A copy of the linked article is here because in typical MSDN style their link is dead.)

Alex K.
Useful information here. However, not really what I was looking for. I am actually looking for a utility which will check the registry file for unused space and get rid of it.
Vulcan Eager
According to my "windows Internals" book; "You can compact the registry by backing it up and restoring it using the Windows RegSaveKey and RegReplaceKey functions, which are used by the Windows Backup utility.)"
Alex K.
Alex is correct; see also http://technet.microsoft.com/en-us/library/cc750583.aspx
Luke