This article will share with you how to use VBS to delete the specified content in the host file. It is very simple and practical. If you need it, you can refer to it. Required: The following three lines have been added to the original host:
202.102.101.105 intranet. corp
202.102.101.107 mail. intranet. corp
202.102.101.108 sip. intranet. corp
No need for the three lines, so run the above vbs code to delete the three lines of the host file
'This script requires the execution user to have the local administrator permission Const ForReading = 1, ForWriting = 2, ForAppending = 8, ReadOnly = 1 Set fso = CreateObject ("Scripting. fileSystemObject ") Set WshShell = CreateObject (" WScript. shell ") 'windir is the windows Installation Directory WinDir = WshShell. expandEnvironmentStrings ("% WinDir %") 'sets the host file directory HostsFile = WinDir & "\ System32 \ Drivers \ etc \ Hosts"' to check whether the host file is read-only, for example, read-only, modify the File Attribute Set objFSO = CreateObject ("Scripting. fileSystemObject ") Set objFile = objFSO. getFile (HostsFile) If objFile. attributes And ReadOnly Then objFile. attributes = objFile. attributes Xor ReadOnlyEnd If Set objFSO = CreateObject ("Scripting. fileSystemObject ") Set objFile = objFSO. openTextFile (HostsFile, ForReading, true) 'checks whether the host file has been changed. If yes, the script hostfileline = "" Do Until objFile is no longer executed. atEndOfStream strline = objfile. readLineIf InStr (strline, "202.102.101.105") <> 0 Or (InStr (strline, "202.102.101.107") <> 0 Or (InStr (strline, "202.102.101.108 ")) then strline = "" End If hostfileline = hostfileline + vbCrLf + strlineLoopWScript. echo hostfilelineobjFile. close 'modify the host file Set filetxt = fso. openTextFile (HostsFile, ForWriting) filetxt. write hostfilelinefiletxt. closeWScript. quit
For more articles about how to use vbs to delete the domain address of the host file, refer to PHP!