国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > VBScript > 正文

使用vbs刪除host文件域址內(nèi)容

2020-07-26 11:45:27
字體:
供稿:網(wǎng)友

要求:原先host里面已增加以下3行

202.102.101.105 intranet.corp
202.102.101.107 mail.intranet.corp
202.102.101.108 sip.intranet.corp

之后不需要此3行內(nèi)容,所以運(yùn)行以上vbs代碼,來刪除host文件此3行

'該腳本要求執(zhí)行用戶有本地管理員權(quán)限Const ForReading = 1, ForWriting = 2, ForAppending = 8, ReadOnly = 1Set fso = CreateObject("Scripting.FileSystemObject")Set WshShell=CreateObject("WScript.Shell")'WinDir 為windows安裝目錄WinDir =WshShell.ExpandEnvironmentStrings("%WinDir%")'設(shè)定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 ReadOnlyEnd IfSet objFSO = CreateObject("Scripting.FileSystemObject")Set objFile = objFSO.OpenTextFile(HostsFile, ForReading,true)'檢查host文件里面是否已經(jīng)更改過了,如果更改過,則不再執(zhí)行腳本hostfileline=""Do Until objFile.AtEndOfStreamstrline = 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'修改host文件Set filetxt = fso.OpenTextFile(HostsFile, ForWriting )filetxt.Write hostfilelinefiletxt.CloseWScript.Quit

發(fā)表評論 共有條評論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 尼玛县| 卢氏县| 祁东县| 吉安市| 泸西县| 平塘县| 康保县| 陵川县| 永安市| 长岭县| 奉化市| 高邑县| 兖州市| 绥江县| 靖宇县| 开远市| 景谷| 奇台县| 岗巴县| 阿克陶县| 宜章县| 新竹市| 山东| 南城县| 新蔡县| 伽师县| 哈尔滨市| 敖汉旗| 柯坪县| 澄城县| 广南县| 新安县| 调兵山市| 健康| 乌拉特中旗| 武清区| 永新县| 昆山市| 伊川县| 克山县| 广元市|