使用vbs删除host文件域址内容
要求:原先host里面已增加以下3行
202.102.101.105intranet.corp
202.102.101.107mail.intranet.corp
202.102.101.108sip.intranet.corp
之后不需要此3行内容,所以运行以上vbs代码,来删除host文件此3行
'该脚本要求执行用户有本地管理员权限
ConstForReading=1,ForWriting=2,ForAppending=8,ReadOnly=1
Setfso=CreateObject("Scripting.FileSystemObject")
SetWshShell=CreateObject("WScript.Shell")
'WinDir为windows安装目录
WinDir=WshShell.ExpandEnvironmentStrings("%WinDir%")
'设定host文件目录
HostsFile=WinDir&"\System32\Drivers\etc\Hosts"
'检查host文件是否为只读,如为只读,则修改文件属性
SetobjFSO=CreateObject("Scripting.FileSystemObject")
SetobjFile=objFSO.GetFile(HostsFile)
IfobjFile.AttributesAndReadOnlyThen
objFile.Attributes=objFile.AttributesXorReadOnly
EndIf
SetobjFSO=CreateObject("Scripting.FileSystemObject")
SetobjFile=objFSO.OpenTextFile(HostsFile,ForReading,true)
'检查host文件里面是否已经更改过了,如果更改过,则不再执行脚本
hostfileline=""
DoUntilobjFile.AtEndOfStream
strline=objfile.ReadLine
IfInStr(strline,"202.102.101.105")<>0Or(InStr(strline,"202.102.101.107"))<>0Or(InStr(strline,"202.102.101.108"))Then
strline=""
EndIf
hostfileline=hostfileline+vbCrLf+strline
Loop
WScript.Echohostfileline
objFile.Close
'修改host文件
Setfiletxt=fso.OpenTextFile(HostsFile,ForWriting)
filetxt.Writehostfileline
filetxt.Close
WScript.Quit
热门推荐
1 训练狗狗憋尿
2 狗狗追踪训练
3 狗狗训练要多少钱
5 深圳狗狗训练
6 训练狗狗唤回
7 狗狗叫怎么训练
8 狗狗训练班
10 狗狗社会化训练
11 狗狗叫回训练
12 广州狗狗训练学校
13 狗狗训练躺下
14 狗狗随行训练
15 训练狗狗巡回
16 狗狗要怎么训练
17 狗狗喂食训练
18 训练狗狗躺下