How do you associate the .exe file extension with a program in Windows?

16

6

A few years ago I saw somebody play a prank on somebody by associating the .exe file extension with Internet Explorer. This made Internet Explorer open up every time the person wanted to start a program.

Unfortunately, I forgot how this was done. I tried to use the Default Programs > Set Associations Control Panel tool, but it didn't list .exe.

How could one set this file association, and, perhaps more importantly, how could one unset it?

Peter Olson

Posted 2011-11-07T14:06:04.830

Reputation: 360

it's on a batch virus google search – RobotHumans – 2011-11-07T14:08:13.037

Answers

20

When doing "pranks" like that, it is not enough to just follow a step-by-step tutorial or a batch script; it's best to know something about how the actual data is stored – it becomes easier to recover later.

All file associations are kept in Registry, which can be edited using regedit or reg. The shell looks for them under HKEY_CLASSES_ROOT, which is a merged view of HKEY_LOCAL_MACHINE\Software\Classes (system-wide) and HKEY_CURRENT_USER\Software\Classes (user-local).

  • [ HKEY_CLASS_ROOT ]
    • [ .txt ]
      • (default) = " txtfile " – pointer to another key under HKCR
    • [ txtfile ]
      • (default) = " Text Document " – textual description as displayed in Explorer
      • [ shell ] – the actions to use for double-click and context-menu
        • (default) = (not set) – the action to use on double-click; defaults to "open"
        • [ open ]
          • (default) = (not set) – label displayed in context menu; defaults to "Open"
          • [ command ]
            • (default) = " %SystemRoot%\system32\NOTEPAD.EXE %1 "

For most extensions, the HKCR\.extn\(Default) value points to a file type key under the same HKCR; for example, .exe points to HKCR\exefile.

(In rare cases, though, all information is under the extension's key directly, with HKCR\.extn\(Default) containing the description. These seem to be very rare, though – maybe a leftover of Windows 9x or 3.x...)

Make backups. reg save HKLM\Software\Classes hklm-classes.hiv Also, remember that the Command Prompt does not care about extensions; if you try to run an executable program, it will always run no matter how it is named, or what its extension is associated with.

user1686

Posted 2011-11-07T14:06:04.830

Reputation: 283 655

1Obviously export the registry before doing any changes like this! :) – HaydnWVN – 2011-11-07T14:34:33.220

@HaydnWVN: reg save takes care of that (and also includes metadata, which reg export would skip). – user1686 – 2011-11-07T14:35:17.710

Ah sorry, replied before your Make backups edit was posted! ;) – HaydnWVN – 2011-11-07T14:36:42.157

1

Don't forget that viewing the raw registry is somewhat the hard way of doing things here. Microsoft's bundled command interpreter has FTYPE and ASSOC commands, and the file type list is also accessible via dialogue boxes in Windows Explorer directly.

– JdeBP – 2011-11-07T14:38:49.313

@JdeBP: AFAIK, Windows Vista got rid of the editor in Explorer - now it just selects the default action. (I haven't dug deeper, though; still using XP here.) Also, the graphical regedit gives a nice overview. – user1686 – 2011-11-07T14:41:38.873

2

Try this:

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\.exe]
@="exefile"
"Content Type"="application/x-msdownload"

[HKEY_CLASSES_ROOT\.exe\PersistentHandler]
@="{098f2470-bae0-11cd-b579-08002b30bfeb}"

kinokijuf

Posted 2011-11-07T14:06:04.830

Reputation: 7 734