Hacking the context menu on Windows

I use Gedit, my favorite text editor, even on Windows. Often I just want to use it to see what’s inside some text file that doesn’t have a “.txt” extension, but the way to do that on Windows XP is just simply brain-dead:

  • Right click.
  • “Open”.
  • See a dialog claiming that “Windows cannot open this file.” LIES! ALL LIES!
  • Click “Select the program from a list.”
  • Scroll scroll scroll through a huge-ass list until you get to Gedit.

This is one of those little annoyances that make working with computers unpleasant, so the other day I resolved to fix it. The information in the first Google screenful was sketchy and I had to patch it together, so I know for certain that next time I have to do it, I won’t remember what I did. Hence this post. Of course, it will work with any other program than Gedit too, so hopefully this will be helpful to somebody.

The easiest way is to put a link to the Gedit executable in C:\Documents and Settings\<username>\SendTo. That way, Gedit will show up in the Send To menu when you right-click on a file. But there’s a better way for even lazier people:

Open Regedit (Windows+R, regedit, enter) and go to HKEY_CLASSES_ROOT/*/shell. The “shell” key didn’t exist at first, so I had to create it. Then under the “shell” key, just create a new key and call it “Open with Gedit” or whatever you want the menu item to be.

Then create a new key under “Open with Gedit” and call it “command”, with a lowercase ‘c’. Double click on the “(Default)” value in it, and enter

C:\Program Files\Gedit\bin\gedit.exe "%1"

or wherever your Gedit executable is located. I found that leaving out the quotes around “%1” also works, but then the filename displayed in Gedit is mangled to fit 8.3, like “ELECTR~5.CSV”.

After reciting this incantation, you can right-click on any file and there it is, “Open with Gedit”. Wow, that was the easiest, and not at all obscure, piece of cake ever!