WebDev.WebServer.exe, with .Net Framework 3.5, is located in “%ProgramFiles%\Common Files\microsoft shared\DevServer\9.0\”.
It is a handy small web server that executes .Net code. Combine jQuery UI with server-side support provided by WebServer and back-end code in .Net. Could this replace desktop applications soon?
To run the web server from a batch file, using the folder where the batch file resides as a root, put the following line in the batch file:
"%programfiles%\Common Files\microsoft shared\DevServer\9.0\WebDev.WebServer.exe" /path:"%cd%"
To create a context menu for a folder that runs the web server in the selected folder, do the steps below. Alternatively, you can copy the following lines into a .reg file and run it:
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\Directory\shell\WebServer]
@="Start Web Server here"
[HKEY_CLASSES_ROOT\Directory\shell\WebServer\command]
@="\"c:\\program files\\Common Files\\microsoft shared\\DevServer\\9.0\\WebDev.WebServer.exe\" /path:\"%L\""
Eventually change the path to %ProgramFiles%. The steps to do this manually are below:
- Open Registry Editor (regedit) and go to HKEY_CLASSES_ROOT\Directory\shell,
- Create a new Key and give it a meaningful name (WebServer, for example),
- Edit the (default) value and enter the description (i.e. "Start Web Server here"),
- Add the new sub-key called "command",
- Set the (default) value to
"c:\program files\Common Files\microsoft shared\DevServer\9.0\WebDev.WebServer.exe" /path:"%L"
The results will be visible immediately. Simply right-click any folder and your entry will be there. Clicking it will run the web server in the selected folder. [Check
this article for registry locations for context menu handlers.]
Edit the parameters (/port, /path, /vpath) additionally to suit your needs. These values will use default and run the Web Server at port 80 with the URL of "http://localhost/". There is no virtual (sub-)directory. The web server will crash if there is IIS (or another web server) occupying the port.
Another possible way to do this is by using the Windows Scripting Host. Create a .js file with the following contents:
var oShell = new ActiveXObject("WScript.Shell");
var oFSO = new ActiveXObject("Scripting.FileSystemObject");
var sCurFolder = oFSO.GetParentFolderName(WScript.ScriptFullName);
oShell.CurrentDirectory = sCurFolder;
// to display info, use:
// WScript.Echo('wscript.echo');
// oShell.Popup('test');
var wshEnv = oShell.Environment("PROCESS");
var sProgFiles = wshEnv("ProgramFiles");
var cmd = '"' + sProgFiles + '\\Common Files\\microsoft shared\\DevServer\\9.0\\WebDev.WebServer.exe" /path:"' + sCurFolder + '"';
// Run the web server.
oShell.Run(cmd);
// Run the browser.
oShell.Run("http://localhost/");