Exemple #1
0
        public static void RemoveHostsFileEntry(String hostName)
        {
            String path = Environment.GetFolderPath(Environment.SpecialFolder.System);

            path = Path.Combine(path, @"drivers\etc\hosts");

            HostsFile file = new HostsFile(path);

            HostsFile.HostEntry entry = file.HostEntries.Find(e => e.HostName.Equals(hostName, StringComparison.OrdinalIgnoreCase));
            if (entry != null)
            {
                file.Elements.Remove(entry);
            }

            file.Save(path);
        }
Exemple #2
0
        public static void AddHostsFileEntry(String hostName, String ipAddress)
        {
            String path = Environment.GetFolderPath(Environment.SpecialFolder.System);

            path = Path.Combine(path, @"drivers\etc\hosts");

            HostsFile file = new HostsFile(path);

            HostsFile.HostEntry e = new HostsFile.HostEntry()
            {
                IPAddress = ipAddress,
                HostName  = hostName,
                Comment   = "Added by PinkEgoBox"
            };

            file.Elements.Add(e);

            file.Save(path);
        }