If you’re like me, you spend a lot of time dealing with files and text files are no exception. Doing anything powerful while editing a text file usually isn’t handled by basic programs like Notepad. What editor to use is a bit of a holy war that I won’t get into since it has little to do with this blog entry. Having said that, I prefer to use a powerful editor when dealing with text files because I find that all too often Notepad just doesn’t get the job done as quickly, so I use TextPad. It has several features that I find myself using all too often, so I’ve set it as my default text editor.
This morning I was doing some development and I had to quickly create a (.reg) registry file with which I could quickly set some values in the registry when I needed to. This seemed like a simple enough operation. For the sake of speed, I already had regedit open to the path that I was interested in, so I chose to export it from regedit. Doing so saved a .reg file where I specified and I was free to edit it. I opened up TextPad and make the changes that I needed. In my case I was only changing a single key so I cut everything else out and saved the file. To test things out, I double-clicked on the .reg file and got the typical prompt:
I just made this file, so I did in fact trust it and by clicking “Yes” I expected to get a valid message like this:
However, instead I got this:
What the heck? That’s not good! This simple was dirt simple. After all it only had 3 lines in it. What could have happened? Turns out that encoding can ruin your morning. Taking a look at the message I saw the “… only import binary registry files from …” and I thought “Why does this thing think it’s binary?”. Why, indeed. I opened the file back up in TextPad and rather than just hitting Ctrl+S or Save, I chose "Save As". Doing so presented this menu, and I’ve highlighted my problem:
That’s right. Without me doing anything, TextPad was going to save this file as Unicode. Regedit expects to get .reg files that are ANSI encoded. So I changed the Encoding to ANSI, saved the file, ran it again, and everything worked fine. It caused me some frustration for a good 20 minutes, so hope this helps someone else out.