Use shebang/hashbang in Windows Command Prompt

Yes, this is possible using the PATHEXT environment variable. Which is e.g. also used to register .vbs or .wsh scripts to be run “directly”.

First you need to extend the PATHEXT variable to contain the extension of that serve script (in the following I assume that extension is .foo as I don’t know Node.js)

The default values are something like this:


You need to change it (through the Control Panel) to look like this:


Using the control panel (Control Panel -> System -> Advanced System Settings -> Environment Variables is necessary to persist the value of the PATHEXT variable.

Then you need to register the correct “interpreter” with that extension using the commands FTYPE and ASSOC:

ASSOC .foo=FooScript
FTYPE FooScript=foorunner.exe %1 %*

(The above example is shamelessly taken from the help provided by ftype /?.)

ASSOC and FTYPE will write directly into the registry, so you will need an administrative account to run them.

Leave a Comment