UGTS Document #36 - Last Modified: 8/29/2015 3:23 PM
Registry .reg files and Unicode

The Windows registry is fully Unicode capable in that all registry keys, value names, and string value data can use Unicode characters.

As a storage optimization, strings that are purely ASCII can be stored as ASCII in registry hive files on disk to save space, but when the values are read from a hive into memory, all strings are stored in memory as Unicode.

By default, regedit will save .reg files as Unicode text files in little endian format with the BOM 0xFFFE at the front of the file.

If you try to edit a .reg file in a text editor which saves the file as Unicode but removes this BOM, regedit will no longer be able to open the file, and you'll get the error, 'The specified file is not a registry script'. You'll also get this error if the file is save as big-ending unicode, with or without a valid BOM sequence.

If your .reg file is only ASCII, you can get around this problem very simply - just save the .reg file in your text editor as ASCII instead, and then import it - regedit doesn't require a BOM sequence for ASCII .reg files (for backwards compatibility with windows 9x).

Alternatively, you can save the .reg file as little-endian Unicode, and have your text editor add a BOM sequence to the saved file. If the text editor doesn't give you this option, then you can use HxD or a similar hex editor to add a 0xFFFE sequence to the beginning of the file yourself.

If you're using Textpad as your text editor, the easiest way to ensure that the proper BOM is added when saving .reg files, is to add a Regedit document class handling .reg files, and then set the Document Class option, 'Write Unicode and UTF-8 BOM'.