Home > Web Front-end > JS Tutorial > body text

Use vbs to delete the domain address content of the host file

高洛峰
Release: 2017-01-16 10:34:27
Original
1598 people have browsed it

Requirements: The following 3 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

You don’t need these 3 lines in the future, so run the above vbs code to delete these 3 lines in the host file

'该脚本要求执行用户有本地管理员权限
Const ForReading = 1, ForWriting = 2, ForAppending = 8, ReadOnly = 1
Set fso = CreateObject("Scripting.FileSystemObject")
Set WshShell=CreateObject("WScript.Shell")
'WinDir 为windows安装目录
WinDir =WshShell.ExpandEnvironmentStrings("%WinDir%")
'设定host 文件目录
 
HostsFile = WinDir & "\System32\Drivers\etc\Hosts"
'检查host文件是否为只读,如为只读,则修改文件属性
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 objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile(HostsFile, ForReading,true)
 
'检查host文件里面是否已经更改过了,如果更改过,则不再执行脚本
hostfileline=""
Do Until objFile.AtEndOfStream
 
strline = objfile.ReadLine
If 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+strline
Loop
WScript.Echo hostfileline
objFile.Close
 
 
&#39;修改host文件
Set filetxt = fso.OpenTextFile(HostsFile, ForWriting )
filetxt.Write hostfileline
filetxt.Close
WScript.Quit
Copy after login

For more articles related to using vbs to delete the domain address content of the host file, please pay attention to the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template