Use VBS to delete host file domain address content _vbs

Source: Internet
Author: User

Requirements: The original host has increased the following 3 lines

202.102.101.105 Intranet.corp
202.102.101.107 Mail.intranet.corp
202.102.101.108 Sip.intranet.corp

This 3-line content is not required, so run the above VBS code to delete the host file 3 lines

' This script requires the execution user to have local Administrator privileges Const ForReading = 1, ForWriting = 2, ForAppending = 8, ReadOnly = 1 Set fso = CreateObject ("Scripting . FileSystemObject ") Set wshshell=createobject (" Wscript.Shell ") ' Windir for Windows installation directory windir = WSHShell.ExpandEnvironmentStrings ("%WinDir%") ' Set host file directory Hostsfile = windir & ' \system32\drivers\etc\hosts ' Check that the host file is read-only and, if read-only, modify the file properties set objFSO = CreateObject ("Scripting.FileSystemObject") Set objfile = Objfso.getfile ( Hostsfile) If objfile.attributes and ReadOnly Then objfile.attributes = objfile.attributes Xor ReadOnly End If Set objf so = CreateObject ("Scripting.FileSystemObject") Set objfile = objFSO.OpenTextFile (hostsfile, Forreading,true) ' Check if the host file has changed, and if so, the script hostfileline= "" do Until objfile.atendofstream strline = objfile will no longer be executed. ReadLine If InStr (strline, "202.102.101.105") <> 0 or (INSTR (strline, "202.102.101.107")) <>0 Or (InStr (Strl INE, "202.102.101.108")) Then strline= "" "End If hostfileline=hostfileline+vbcrlf+strline Loop WSCRIpt. Echo hostfileline objfile.close ' Modify host file Set Filetxt = fso. OpenTextFile (Hostsfile, ForWriting) filetxt. Write hostfileline Filetxt.
 Close Wscript.Quit

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.