Is there any shell extension for Explorer that would execute text files with a #! shebang at the beginning?

  • You might try to add the file type extension to the registry so that it executes the given program on run or do something like this.
    – new123456
    Jun 23, 2011 at 5:11
  • 2
    I don't think so. The registry only holds suffixes. I Googled around, but could not find anything.
    – KCotreau
    Jun 23, 2011 at 5:26
  • Hmm... does this work?
    – new123456
    Jun 23, 2011 at 5:38
  • You need to be more specific... What kind of executable are you tying to create? Did you change permissions to make your "Text File" executable? What shell are you trying to use (e.g. #!/bin/bash) ?
    – chrsblck
    Jun 23, 2011 at 8:28
  • @chrsblck But I don’t remember Windows supporting marking things “executable”…
    – binki
    Dec 26, 2015 at 17:09

2 Answers 2


You're very much in conflict with the Microsoft model for files. In the POSIX model, the filename doesn't dictate whether a file is executable, at all. That's solely the province of the permissions. In the Microsoft model used in Windows Explorer, whether a file is executable is also determined by its filename, in particular by the extension. Hence the FTYPE command, the ASSOC command, the PATHEXT environment variable, and so forth.

So, with the proviso that this is restricted to files with the .CMD extension, in order to fit in with the aforementioned model, there actually is an extension that will pass files beginning with #! to the script interpreter named on that line. It's JP Software's TCC, a replacement command interpreter which has both #! and EXTPROC support. Explorer can be told to hand off all .CMD files to TCC, which in turn will read the #! and hand off to the named script interpreter.

If you want to use #! with any other file extensions in Explorer, then you hit the paradigm conflict, and you'll have to switch to using file extension associations, just like the person with the CGI script did in the article hyperlinked-to by new123456. Extension determining script interpreter, not magic numbers in file contents, is the paradigm that Windows Explorer uses.


If your text file happens to by a Python File then you can do exactly what you want using pylauncher.
From the docs:

PEP 397 compatible launcher for Python under Windows. See http://www.python.org/dev/peps/pep-0397/ for PEP, http://www.red-dove.com/screencasts/launcher/la... for screencast

  • 1
    According to their documentation you can also use it to launch arbitrary programs from the shebang, with the caveat that they must be in the system %PATH% because that's where Python searches for the application.
    – dragon788
    Jul 13, 2016 at 22:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.