Skip to content

Instantly share code, notes, and snippets.

@nvivo
Created August 5, 2016 15:01
Show Gist options
  • Save nvivo/59c81b106132a9f928f9a7314def15c5 to your computer and use it in GitHub Desktop.
Save nvivo/59c81b106132a9f928f9a7314def15c5 to your computer and use it in GitHub Desktop.
Start IIS Express from Here and open the browser
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Directory\shell\IISExpress]
@="IIS Express Here"
[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Directory\shell\IISExpress\command]
@="D:\\Bin\\StartIISExpress.exe %V"
[HKEY_CLASSES_ROOT\Directory\Background\shell\IISExpress]
@="IIS Express Here"
[HKEY_CLASSES_ROOT\Directory\Background\shell\IISExpress\command]
@="D:\\Bin\\StartIISExpress.exe %V"
using System;
using System.Diagnostics;
using System.Threading;
namespace StartIISExpress
{
class Program
{
static void Main(string[] args)
{
var path = args.Length > 0 ? args[0] : Environment.CurrentDirectory;
var rnd = new Random();
var port = rnd.Next(1024, 65535);
var psi = new ProcessStartInfo
{
WorkingDirectory = "C:\\Program Files (x86)\\IIS Express",
FileName = "iisexpress.exe",
Arguments = $"/port:{port} /path:\"{path}\"",
UseShellExecute = true
};
Process.Start(psi);
Thread.Sleep(500);
Process.Start($"http://localhost:{port}");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment