“The specified file is not a registry script” – How encoding can ruin your morning

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:

Registry File Import 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:

Registry File Import

However, instead I got this:

Registry File Import Failed

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:

Registry File Textpad Save As

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.

Advertisements

26 thoughts on ““The specified file is not a registry script” – How encoding can ruin your morning”

  1. Exceedingly glad this worked for you… but nothing I’ve tried will let me install this script in the registry. ANSI or Unicode, it insists that I can only import registry files from a binary editor.

    Nice try, though.

    1. Nice try indeed. I can pretty much guarantee you that if you created your file by hand in Notepad that it should work. If not, you’re either facing an encoding issue or it’s not in the correct format that it expects. Considering the error message, I’d go with the former. Try looking at the file in a hex editor and see what you get.

  2. Sir, your solution for the registry regarding ANSI was perfect. It solved my problem. The other thing I had to do was specify “all files” as it wanted to save it as “txt”.

    Thank you very much!

    Dale

  3. This is great! Thank you very much!! It solved my problem that I was stuck on for few days and no amount of googling gave me the answer you have provided in a lucid way.
    Thanks again!

  4. Yep, just run into this – tested alongside notepad (export – open in editor (np/tp) – add a space and then delete it again so can save – save – import – which worked fine for np and fails with tp) – took me a while to work it out, then thought I’d moan to TextPad – but found your post (if only I had found it 3 hours ago!)

  5. Hi crmdev,
    While your solution to save a .reg file as ANSI actually works perfectly well, the fact remains that the Registry Editor exports these files as Unicode (UTF-16, little Endian to be exact)!
    The only difference between this Unicode Format and the default Textpad Unicode Format is the inclusion of a BOM (Byte Order Mark), namely FF FE, at the start of the .reg file to define it as UTF-16, little Endian!
    Textpad does not fail us in this respect.
    The permanent solution is to Configure a New Document Class:
    For a visual presentation on how to achieve this go to:
    TextPad Registry File Corruption Solution

  6. Man what a nightmare. I had no idea what the heck was going on when some reg files were working and others weren’t. Turns out, any reg file I made on my Windows 7 machine worked, but the ones I made in Windows 8 didn’t. Turns out Windows 8’s notepad automatically saves in Unicode.

    Thanks for the tip!

  7. Thanks a lot

    i was going crazy

    it worked on win2008 R2 and it didnt work on win2008 R2 SP1

    I was shure it was a security issue

    Luckily i found U and its a editor issue

    Im getting ready for daylight saving time and the only way to modify is via regedit

    HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Time Zones\Israel Standard Time\Dynamic DST\

    so I exported

    copied

    edit

    save

    till now on win2003 I using command timezone /s with doesnt work

    thank again

    yehuda

  8. This got me going enough to figure out that I cannot use a leading “;” to begin a comment. Removed comments and works fine.

    Thanks for your info.

  9. I found that this did not work until I added this to the top of the file:

    Windows Registry Editor Version 5.00

  10. Thanks. This helped. Note, I’ve had this same problem with saving PHP files in Textpad. Remember to remove the BOM

  11. Thanks dude its works like charm…

    I wasted my 4 hours until I could not approach to you…
    Thank you so much…..

  12. Thank you!!! The instructions were exactly what I needed when running an msi installer for the first time on a Server 2012 system, only Server 2003 before so never a problem. I didn’t catch in your notes about starting with an exported reg entry. That was key for getting this to work. Thank you!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s