public bool unblockwebsite(string strurlunblock) { try { string tempFile = Path.GetTempFileName(); string hostpath = Environment.GetEnvironmentVariable("windir") + "\\System32\\drivers\\etc\\hosts"; using (StreamReader sr = new StreamReader(hostpath)) { using (StreamWriter sw = new StreamWriter(tempFile)) { string line; while ((line = sr.ReadLine()) != null) { if (line != " 127.0.0.1" + " " + strurlunblock) sw.WriteLine(line); } sw.Close(); } sr.Close(); } //File.Delete(hostpath); //File.Move(tempFile, hostpath); if (File.Exists(tempFile)) File.Copy(tempFile, hostpath, true); return true; } catch { return false; } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)