Change your window's hosts file from C# or Powershell.
C# PowerShell
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
PSHostsFile
PSHostsFileTest
lib
packages
tools
.gitignore
Build.ps1
LICENSE.txt
PSHostsFile.sln
RunNUnitGUI.ps1
default.ps1
readme.md

readme.md

Check out Carbon (http://get-carbon.org/) for a much more capable powershell automation libary.

Install via nuget (http://nuget.org/List/Packages/PSHostsFile). Or run .\build.ps1 and use the PSHostsFile.dll.

Powershell:

import-module .\PSHostsFile.dll
        
get-HostsFileEntry
remove-HostsFileEntry <hostName>
set-HostsFileEntry <hostName> <Address>

C#:

using PSHostsFile;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            foreach (var hostsEntry in HostsFile.Get())
            {
                System.Console.WriteLine("Have host {0} - {1}.", hostsEntry.Hostname, hostsEntry.Address);
            }

            HostsFile.Set("foo.example.com", "127.0.0.1");  //  Add or update the hosts file entry for foo.example.com
            HostsFile.Set("another.example.com", "127.0.0.1");
            HostsFile.Remove("another.example.com");  //  Remove a hosts file entry
        }
    }
}