Advertisement
kilya

Edit_Hosts_File

May 19th, 2020
1,329
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.71 KB | None | 0 0
  1. using System;
  2. using System.IO;
  3. using System.Windows.Forms;
  4.  
  5. namespace Edit_Host
  6. {
  7.     public partial class Form1 : Form
  8.     {
  9.         public Form1()
  10.         {
  11.             InitializeComponent();
  12.         }
  13.  
  14.         private void button1_Click(object sender, EventArgs e)
  15.         {
  16.             try
  17.             {
  18.                 using (StreamWriter sw = File.AppendText(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.System), @"drivers\etc\hosts")))
  19.                 {
  20.                     sw.WriteLine("127.0.0.1 websiteDomaine");
  21.                 }
  22.             }
  23.             catch (Exception ex)
  24.             {
  25.                 MessageBox.Show(ex.Message);
  26.             }
  27.         }
  28.     }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement