Is is possible to modify this script to delete entries in the hosts file?
Code:
strSrcFile = objShell.ExpandEnvironmentStrings("%SYSTEMROOT%") & "\System32\Drivers\Etc\Hosts"
Set objFSO = CreateObject("Scripting.FileSystemObject")
arrHosts = Array(_
"192.168.0.1 server.com", _
"196.213.0.10 ", _
"196.213.0.10 ", _
"192.168.0.2 server.com", _
"192.168.0.3 server.com", _
"192.168.0.4 server.com", _
"192.168.0.5 server.com", _
"192.168.0.6 server.com" _
)
If objFSO.FileExists(strSrcFile) = True Then
Set objFile = objFSO.OpenTextFile(strSrcFile, 1, False)
strContents = objFile.ReadAll
objFile.Close
Set objFile = Nothing
arrContents = Split(strContents, VbCrLf)
For Each strHost In arrHosts
strIPAddress = Split(strHost, vbTab)(0)
strDNSName = Split(strHost, vbTab)(1)
boolHostFound = False
For intLine = LBound(arrContents) To UBound(arrContents)
If InStr(arrContents(intLine), strIPAddress) > 1 Or InStr(arrContents(intLine), strDNSName) > 1 Then
boolHostFound = True
arrContents(intLine) = strIPAddress & vbTab & strDNSName
End If
Next
If boolHostFound = False Then
ReDim Preserve arrContents(UBound(arrContents) + 1)
arrContents(UBound(arrContents)) = strIPAddress & vbTab & strDNSName
End If
Next
Set objFile = objFSO.CreateTextFile(strSrcFile, True)
objFile.Write Join(arrContents, VbCrLf)
objFile.Close
Set objFile = Nothing
MsgBox "File modified."
Else
MsgBox "File not found."
End If