组策略脚本->向host文件增加一条记录

上一篇 / 下一篇  2006-06-03 01:55:00 / 个人分类:Microsoft

来了一个新的需求,需要向一个.vbs脚本,向host文件增加一条记录:就是 IP   域名;然后通过组策略推下去。

很简单的一个脚本,不过为了方便领导观看,写的注释挺全的,便发一下吧......

Dim fso, objFile, rs,ws,fileString,i                    '定义变量
Set fso = CreateObject("Scripting.FileSystemObject")  '创建一个FSO
Set objFile = fso.GetFile("C:\WINDOWS\system32\drivers\etc\hosts")      '得到文件的句柄
Set rs = objFile.OpenAsTextStream(1,-2)    'host没有扩展名,不能用opentextstream打开,rs文件对象读取host文件内容
Set ws = objFile.OpenAsTextStream(8,-2)     ' ws文件对象写入记录
fileString = rs.ReadAll()       '将host文件作为字符串读出
Msgbox(fileString)       '正式使用的时候可以将msgbox全句去掉
subhost = "168.3.1.13"  
i = InStr(fileString,subhost)      '判断IP 是否存在
Msgbox(i)
if i = 0 Then
   Msgbox("不存在该记录,写入")
   ws.writeLine("168.3.1.12       localhost2")
else
  Msgbox("该记录已经存在!")
end if
rs.close()  '关闭文件对象
ws.close()  '同上

 

 


TAG:

 

评分:0

我来说两句

显示全部

:loveliness: :handshake :victory: :funk: :time: :kiss: :call: :hug: :lol :'( :Q :L ;P :$ :P :o :@ :D :( :)

日历

« 2008-08-19  
     12
3456789
10111213141516
17181920212223
24252627282930
31      

数据统计

  • 访问量: 792
  • 日志数: 9
  • 建立时间: 2005-09-07
  • 更新时间: 2008-04-07

RSS订阅

Open Toolbar