
用VB来修改hosts应该怎么写代码(高分悬赏)
PrivateSubCommand1_Click()Open"C:\WINDOWS\system32\drivers\etc\hosts"ForOutputAs#2Pri...
Private Sub Command1_Click()
Open "C:\WINDOWS\system32\drivers\etc\hosts" For Output As #2
Print #2, Text1.Text
End Sub
这段代码怎么不行?哪里有错误吗 单击后 hosts文件怎么变空白了 里面字都没有。请求高手 帮忙修改下 展开
Open "C:\WINDOWS\system32\drivers\etc\hosts" For Output As #2
Print #2, Text1.Text
End Sub
这段代码怎么不行?哪里有错误吗 单击后 hosts文件怎么变空白了 里面字都没有。请求高手 帮忙修改下 展开
展开全部
Private Sub Command1_Click()
Open "C:\WINDOWS\system32\drivers\etc\hosts" For append As #2
Print #2, Text1.Text
close #2
End Sub
这样写就好了。
Open "C:\WINDOWS\system32\drivers\etc\hosts" For append As #2
Print #2, Text1.Text
close #2
End Sub
这样写就好了。
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
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 Form_Load()
Command1.Caption = "读入Host"
Command2.Caption = "写入Host"
Command3.Caption = "修改"
Text1 = ""
Text2 = ""
End Sub
Private Sub List1_Click()
If Left(List1, 1) = "#" Then
'注释行
Text1 = List1.Text
Text2 = ""
Else
Dim i As Integer
i = InStr(1, List1.Text, " ")
Text1 = Left(List1.Text, i - 1)
Text2 = Trim(Mid(List1.Text, i))
End If
End Sub
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 Form_Load()
Command1.Caption = "读入Host"
Command2.Caption = "写入Host"
Command3.Caption = "修改"
Text1 = ""
Text2 = ""
End Sub
Private Sub List1_Click()
If Left(List1, 1) = "#" Then
'注释行
Text1 = List1.Text
Text2 = ""
Else
Dim i As Integer
i = InStr(1, List1.Text, " ")
Text1 = Left(List1.Text, i - 1)
Text2 = Trim(Mid(List1.Text, i))
End If
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询