Add a "Web Server Here" Explorer shell extension command

Sometimes I just want to spin up a web server on a folder in explorer. Often its because browsers get nervous about running HTML pages directly off the file system and seem to feel more comfortable when its served from a web server. I figured I'd had enough of writing little scripts or using IIS to create virtual folders every time and wanted a context menu option in Windows Explorer that'll just launch a web server pretty much anywhere I wanted. Here's what it'll look like:

image

Turns out, this is fairly straightforward to accomplish using IIS Express and some registry tweaks. For those of you who don't know, IIS Express is this light weight, self-contained version of IIS meant to be used for developing, debugging and testing web apps. When you use Visual Studio, the web apps themselves run inside IIS Express when you hit F5. Being self-contained, we are able to run a web server pretty much anywhere from a command prompt. Documentation on how to do this is available here. You can download and install IIS Express either via the Web Platform Installer or from here (IIS Express version 8.0 at the time of writing). If your web app files are located in say, D:\Code\Web\Foo then you'd run a web server from that location like so:

"C:\Program Files (x86)\IIS Express\iisexpress.exe" /path:"D:\Code\Web\Foo" /port:8080 /systray:true

The path to iisexpress.exe might be different if you're running on a 32-bit system. It'll just be "Program Files" instead of "Program Files (x86)". Once you've run the command, the web server starts up and you can load your web app in your favorite browser by navigating to http://localhost:8080/. The next step is to integrate this into the Explorer shell so you can run this from wherever you want directly from Explorer. Phil Haack has written up a post on how to do this with the web server that Visual Studio 2008 used to ship with way back in, well, 2008. I adapted the basic steps described there to make it work with IIS Express. Now, setting this up involves editing the Windows Registry, so please be careful with what you do. This works on my machine and that's about all I am willing to say!

works-on-my-machine-starburst_3

If you're on a 64-bit installation of Windows, here're the changes you need to do to your registry:

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Directory\shell\IISExpressWebServer]
@="Web Sever Here"

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Directory\shell\IISExpressWebServer\command]
@="C:\\Program Files (x86)\\IIS Express\\iisexpress.exe /path:\"%1\" /port:8080 /systray:true"

And if you're on a 32-bit installation, then this is what you need to do:

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Directory\shell\IISExpressWebServer]
@="Web Sever Here"

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Directory\shell\IISExpressWebServer\command]
@="C:\\Program Files\\IIS Express\\iisexpress.exe /path:\"%1\" /port:8080 /systray:true"

If you need .reg files so you can just double-click to import them into your registry then they are available here. You might want to edit the .reg files in case your installation paths are different from what's given there. That's pretty much it!

comments powered by Disqus