script syntex

B

bosiydid

Does anyone know how I can insert a line into the 'hosts'
using my logon script that runs from the server? Thank
you.
 
M

Michael Holzemer

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
 
G

Guest

OK,

I took your code, modified the script to look like this....

'// 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, "server.whatever.com") = 0 Then
oHost.close
wscript.sleep 500
Set oHost = oFSO.OpenTextFile(sHost, ForAppending, False)
oHost.writeline vbcrlf
oHost.writeline "x.x.x.x" & vbTab & "server.whatever.com"
End If
oHost.close

If I do this manually it works so I know that the IP and
the server name both work. Any more help you can provide
would be GREATLY appreciated.
 
M

Michael Holzemer

OK,

I took your code, modified the script to look like this....

'// 2003 Michael Holzemer

If I do this manually it works so I know that the IP and
the server name both work. Any more help you can provide
would be GREATLY appreciated.

<snip>

Help doing what? Making it a logon script?

http://support.microsoft.com/default.aspx?scid=kb;en-us;198642&Product=win2000

--
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top