ok, i have sync.bat, and sync2.vbs in the same folder as DansIP.txt
Sync.bat:
@echo off
cls
cd D:\FROMDAN\IP
start D:\FROMDAN\IP\>cscript /nologo sync2.vbs
new ip address dan
pause
I only get the error that new is not an internal/external command.
sync2.vbs:
Set regEx = New RegExp
regEx.Pattern = "\s+" 'pattern to substitute all spaces/tabs with 1 space
Set objFS = CreateObject("Scripting.FileSystemObject")
strFile = "c:\WINDOWS\system32\drivers\etc\hosts.txt"
strIPFile = "D:\FROMDAN\IP\DansIP.txt"
Set objFile = objFS.OpenTextFile(strIPFile,1)
Do Until objFile.AtEndOfStream
strLine = objFile.ReadLine
strLine = regEx.Replace(strLine, " ")
splitted = Split(strLine," ")
strIPtoChange = splitted(0)
strUserName = splitted(1)
Loop
Set objFile = objFS.OpenTextFile(strFile,1)
Do Until objFile.AtEndOfStream
strLine = objFile.ReadLine
If InStr(strLine,strUserName) > 0 Then
splitted = Split(strLine)
splitted(0) = strIPtoChange
strLine = Join(splitted," ")
End If
WScript.Echo strLine
Loop
hosts file remains unchanged.