如何用VB来修改hosts

如何用VB来修改hosts,第1张

Private Sub Command2_Click() '写入,覆盖原来的

Open "c:\1.txt" For Output As #1

Print #1, Text1.Text

Close #1

End Sub

Private Sub Command3_Click() '写入脊明,写入原来的后孙裂面

Open "c:\1.txt" For Append As #1

Print #1, Text1.Text

Close #1

End Sub

'你这个hosts改成路径

dim hosts

hosts="c:\1.txt"

Private Sub Command2_Click() '写入,覆盖樱凯告原来的

Open hosts For Output As #1

Print #1, Text1.Text

Close #1

End Sub

Private Sub Command3_Click() '写入,写入原来的后面

Open hosts For Append As #1

Print #1, Text1.Text

Close #1

End Sub

Private Sub Command1_Click()

Open "厅岁C:\WINDOWS\system32\友猜drivers\etc\hosts" For append As #2

Print #2, Text1.Text

close #2

End Sub

这样写就好了扮告睁。

'添加两个文本框+一个按钮,然后粘贴代码如下

Private Sub Command1_Click()

Dim d() As String, t As String

Dim l As Long

Open "c:\WINDOWS\system32\drivers\etc\hosts" For Input As #1

While Not EOF(1)

Line Input #1, t

t = Trim(t)

If Left(t, 1) <>"#" And Len(t) >0 Then

ReDim Preserve d(0 To l) As String

d(l) = UCase(t)

l = l + 1

End If

Wend

Close #1

For l = 0 To UBound(d)

If InStr(d(l), UCase(Text2.Text)) >0 Then '这里只检查网告亮址,也可以袜好宽改成text1.text就是检查IP的

MsgBox "定义有袜尺重复" &d(l)

Exit Sub

End If

Next l

Open "c:\WINDOWS\system32\drivers\etc\hosts" For Append As #1

Print #1, Text1.Text &" " &Text2.Text

Close #1

End Sub

Private Sub Form_Load()

Text1.Text = "127.0.0.1"

Text2.Text = "www.baidu.com"

End Sub


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/tougao/12213106.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-21
下一篇 2023-05-21

发表评论

登录后才能评论

评论列表(0条)

保存