求修改系统Hosts文件的VB代码!!!!

来源:百度知道 编辑:UC知道 时间:2024/06/28 05:34:07
Hosts文件就在C:\WINDOWS\system32\drivers\etc中,

修改改后的内容可以在代码里修改,结合标签caption或者text的更好了,

主要是能在以后源码编译的时候随便我改变!!!

Option Explicit
Const cstFileName As String = "C:\WINDOWS\system32\drivers\etc\hosts"
'1个List1,2个TextBox,3个Command
Private Sub Command1_Click()
Dim str1 As String
Open cstFileName For Input As #1
While Not EOF(1)
Line Input #1, str1
str1 = Trim(str1)
If Len(str1) Then
List1.AddItem str1
End If
Wend
Close
If List1.ListCount > 0 Then List1.ListIndex = 0
End Sub

Private Sub Command2_Click()
Dim i As Integer
Open cstFileName For Output As #1
For i = 0 To List1.ListCount - 1
Print #1, List1.List(i)
Next i
Close

End Sub

Private Sub Command3_Click()
Dim i As Integer
i = List1.ListIndex
List1.RemoveItem i
List1.AddItem Text1.Text & " " & Text2.Text, i
List1.ListIndex = 1
End Sub

Private Sub