Public Class Form1
Dim Path As String = (My.Computer.FileSystem.SpecialDirectories.AllUsersApplicationData)(0) + ":\Windows\system32\drivers\etc\hosts"
Dim Controllo As Boolean = False
Dim Com As String = "127.0.0.1 rad.msn.com"
Private Sub ControlloComando()
Controllo = False
Dim Leggi As New IO.StreamReader(Path)
Dim Stringa As String = Nothing
While Not (Leggi.EndOfStream)
If Com = Leggi.ReadLine Then
Controllo = True
End If
End While
Leggi.Close()
If Controllo Then
Button1.Enabled = False
Button2.Enabled = True
Else
Button2.Enabled = False
Button1.Enabled = True
End If
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim Leggi As New IO.StreamWriter(Path, True)
Leggi.WriteLine(Com)
Leggi.Close()
ControlloComando()
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim Testo As String = My.Computer.FileSystem.ReadAllText(Path)
Testo = Testo.Replace(Com, "")
My.Computer.FileSystem.WriteAllText(Path, Testo, False)
ControlloComando()
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
ControlloComando()
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
ControlloComando()
End Sub
End Class