Use vbs to delete the domain address of the host file

Source: Internet
Author: User
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!

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.