Tuesday, September 22, 2009

Messed-Up Registry Export

Q: Operating system is Windows XP. I wanted to get a view of some parts of the Registry. I used REGEDIT to export the entirety of HKEY_CURRENT_USER. I reviewed the output in Notepad. It looked fine - nice 80 character lines broken at a backslash character if necessary. I wrote a simple REXX program to process this file and it totally failed. Every line of text had an inserted space between each character. I checked with a hex editor - it was actually 00 byte after each character.
Why does REGEDIT insert these null characters? Why would Notepad display the file as if the nulls didn't exist? It appears Notepad can't be trusted to accurately display files. This is disquieting to say the least. Are there any other problems with Notepad? - Bruce Goetz.






A: Notepad is fine, and REGEDIT is fine. What you didn't realize is that the default REGEDIT export format in XP, Vista, and Windows 7 is Unicode text. Each character occupies two bytes. Since these are actually standard ANSI characters the high byte is always 0. Your REXX program is trying to read the file as if it were standard one-byte ANSI text; naturally that doesn't work.
The best solution is to export the data from REGEDIT as ANSI text. To do so, pull down the "Save as type" list and choose "Win9x/NT4 Registration Files (*.reg)". Now when you export the file it will be in simple ANSI text format and your REXX program will have no trouble reading it. I do this all the time when I want to use the built in FC (File Compare) command to check for differences in Registry settings; FC doesn't handle Unicode text either. - Neil J. Rubenking.

No comments:

Post a Comment