bosiydid said:
Does anyone know how I can insert a line into the 'hosts'
using my logon script that runs from the server? Thank
you.
I do. Watch out for word wrap.
'// 2003 Michael Holzemer
'// Add server(s) to client host file
Option Explicit
Dim sFile, sHost, sSysDir, oHost
Dim oFSO, sCheck
Const WindowsFolder = 0
Const ForReading = 1
Const ForAppending = 8
sFile = "\system32\drivers\etc\hosts"
Set oFSO = CreateObject("Scripting.FileSystemObject")
'// Get the %system% folder
Set sSysDir = oFSO.GetSpecialFolder(WindowsFolder)
sHost = sSysDir & sFile
Set oHost = oFSO.OpenTextFile(sHost, ForReading, False)
sCheck = oHost.readall
If instr(sCheck, "server1.foo.com") = 0 Then
oHost.close
wscript.sleep 500
Set oHost = oFSO.OpenTextFile(sHost, ForAppending, False)
oHost.writeline vbcrlf
oHost.writeline "192.168.4.3" & vbTab & "server1.foo.com"
End If
oHost.close
--
Regards,
Michael Holzemer
No email replies please - reply in newsgroup
Learn script faster by searching here
http://www.microsoft.com/technet/treeview/default.asp?url=/technet/scriptcenter/default.asp