On Error Resume Next
Set wshshell = createobject("wscript.shell")
Line1="0.0.0.0.0 TEST"
Call RemoveValues(Line1)
Sub RemoveValues(Line)
Dim varFile ‘Variable to store the values of the file
Dim varFileLines ‘Variable to store the current line read from the file
Dim WshShell ‘Object pointing to the WScript
‘Initializing the WScript object
Set WshShell = CreateObject("WScript.shell")
‘System root
SysRoot = WshShell.ExpandEnvironmentStrings("%SystemRoot%")
‘File Path
sFileName = SysRoot & "\system32\drivers\etc\Hosts"
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile(sFileName, 1)
‘looping through the Hostss file
Do Until objFile.AtEndOfStream
‘Reading a line from the Hosts file
varFileLines = objFile.ReadLine
‘Checking for the search string
If Trim(varFileLines) <> Line Then
‘Building the string without the search string
If Trim(varFile) = "" Then
varFile = Trim(varFileLines)
Else
varFile = varFile & vbCrLf & Trim(varFileLines)
End If
End If
Loop
‘Closing the file object
objFile.Close
Set objFile = Nothing
‘Creating the file without the search string
Set objFile = objFSO.CreateTextFile(sFileName, True, False)
‘Writing the lines into the file
objFile.WriteLine varFile
‘Closing the file object
objFile.Close
Set objFile = Nothing
End Sub
Thanks, you saved me lots of time..