I used reg.exe in a remote script run from a server to change the dns
AND WINS server info it worked better plus I had info for future
reference You will have to do a subnet scan to get a list to feed this
script.
SEE ATTACHED SCRIPT I HOPE IT HELPS. CHANGE .TXT TO VBS
-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Mulnick, Al
Sent: Thursday, January 06, 2005 9:43 AM
To: '[email protected] '
Subject: RE: [ActiveDir] Bizarre NETSH Behavior - Startup Script on XP
Does that mean that you get the same results even if you use the index?
I can't speak for the 'softies but if you want to report it as a bug,
you either open a case direct off the support pages, else you go through
your support rep. An organization your size/stature, likely has a TAM
of some sort right? That would be a fair way to submit a bug.
Bugs usually result in no-charge service. But I would highly suggest
that you verify that it doesn't work with the index option added prior
else it
*might* work and you'd have a bug to file that would have an expected
workaround.
http://support.microsoft.com/?LN=en-us&scid=fh%3Ben-us%3Bofferprophone&x
=12&
y=4
-----Original Message-----
From: [EMAIL PROTECTED]
To: [email protected]
Cc: [email protected]; [EMAIL PROTECTED]
Sent: 1/6/2005 9:29 AM
Subject: RE: [ActiveDir] Bizarre NETSH Behavior - Startup Script on XP
Hi Al
Any idea how to report it as a bug? I was kind of hoping Microsoft guys
would be monitoring this discussion group and one of them would look
into it / address it internally.
Regards;
James R. Day
Active Directory Core Team
Office of the Chief Information Officer
National Park Service
(202) 354-1464 (direct)
(202) 371-1549 (fax)
[EMAIL PROTECTED]
|---------+---------------------------------->
| | "Mulnick, Al" |
| | <[EMAIL PROTECTED]>|
| | Sent by: |
| | [EMAIL PROTECTED]|
| | tivedir.org |
| | |
| | |
| | 01/05/2005 02:03 PM EST|
| | Please respond to |
| | ActiveDir |
|---------+---------------------------------->
>-----------------------------------------------------------------------
-------------------------------------------------------|
|
|
| To: [email protected]
|
| cc: (bcc: James Day/Contractor/NPS)
|
| Subject: RE: [ActiveDir] Bizarre NETSH Behavior - Startup
Script on XP |
>-----------------------------------------------------------------------
-------------------------------------------------------|
I haven't seen that and it's not what I would expect. I would have
expected a failure instead or replacing the WINS entry.
Do you get the same results if you do use an index?
add dns [name=]InterfaceName [addr=] DNSAddress [[index=]DNSIndex]
It's not listed as 'required' but seems that you should be able to
specify a location for the target.
Might be worth it to report it as a bug.
Al
-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of
[EMAIL PROTECTED]
Sent: Wednesday, January 05, 2005 1:40 PM
To: [email protected]
Subject: [ActiveDir] Bizarre NETSH Behavior - Startup Script on XP
Hi All
I was wondering if anybody else has ever seen this. We were at a
location a few days ago that uses static ip addressing. Initially they
had 1 DNS server and 2 WINS servers for their NT domain. We migrated
them all to our
WIN2K3 Forest and rather then set up DHCP we used the startup script to
change the DNS servers. WINS was being left as it already was setup as
we are considering a WINS redesign right now.
The initial configuration (made up ips)
DNS 65.65.108.5
WINS 1 65.65.10.5
WINS2 65.65.10.6
We used netsh commands to change the addressing.
netsh interface ip set dns "local area connection" static 65.65.150.2
netsh interface ip add dns "local area connection" 65.65.150.4
When we checked the ip configuration on the machines after the startup
script ran we had the following:
DNS 65.65.150.2
WINS1 65.65.10.5
WINS2 65.65.150.4
For some reason the secondary DNS entry was overwriting the secondary
WINS instead. When we put in a line in the startup script to manipulate
WINS netsh interface ip set wins "local area connection" starti
65.65.10.5 We got the expected results (1 Wins server and the 2 DNS
servers we had specified).
Has anybody else seen this behavior? Is this a bug in the NETSH command
or something else. We tested this on 5 different machines, both running
the script via. startup script and manually running it with admin
credentials with the same results.
Regards;
James R. Day
Active Directory Core Team
Office of the Chief Information Officer
National Park Service
(202) 354-1464 (direct)
(202) 371-1549 (fax)
[EMAIL PROTECTED]
List info : http://www.activedir.org/mail_list.htm
List FAQ : http://www.activedir.org/list_faq.htm
List archive:
http://www.mail-archive.com/activedir%40mail.activedir.org/
List info : http://www.activedir.org/mail_list.htm
List FAQ : http://www.activedir.org/list_faq.htm
List archive:
http://www.mail-archive.com/activedir%40mail.activedir.org/
List info : http://www.activedir.org/mail_list.htm
List FAQ : http://www.activedir.org/list_faq.htm
List archive:
http://www.mail-archive.com/activedir%40mail.activedir.org/
List info : http://www.activedir.org/mail_list.htm
List FAQ : http://www.activedir.org/list_faq.htm
List archive:
http://www.mail-archive.com/activedir%40mail.activedir.org/
'THIS SCRIPT WAS MADE WITH THE HELP OF MULTIPLE PARTIES THIS FINAL PRODUCT
WAS PUT TOGETHER BY JONATHAN F. CARR
'USE AT YOUR OWN RISK
'working directory is where it will place the old info files
Set fso = CreateObject("Scripting.FileSystemObject")
wkdir = "c:\jon\exchange\"
'wkdir = objArgs(0)
If (fso.FolderExists(wkdir)) Then
'WScript.Echo wkdir & " exists."
Else
Wscript.echo wkdir & " doesn't exist. Program is exiting"
wscript.quit
End If
' this file is the list of servers to be done
servfile = wkdir & "jon.txt"
'servfile = wkdir & objArgs(1)
If (fso.FileExists(servfile)) Then
'WScript.Echo servfile & " exists."
Else
Wscript.echo servfile & " doesn't exist. The program is exiting"
wscript.quit
End If
' this is where the info is logged
logfile = wkdir & "loging.txt"
'enter the old WINS servers here that you wnat to replace with new values.
Note this is a one for one replacement
'example owinsserver(0) will be changed to nwinsserver(0)
' note that if the owinsserver entry is "" then it will add the corresponding
nwinsserver to the end of the
' server list if it does not exist already
Dim owinsserver(6)
owinsserver(0) = "17.123.213.13"
owinsserver(1) = "17.123.217.13"
owinsserver(2) = ""
owinsserver(3) = ""
owinsserver(4) = ""
owinsserver(5) = ""
Dim nwinsserver(6)
nwinsserver(0) = "17.16.96.99"
nwinsserver(1) = "17.16.96.99"
nwinsserver(2) = "17.16.100.24"
nwinsserver(3) = "17.16.96.110"
nwinsserver(4) = "17.16.100.18"
nwinsserver(5) = "17.17.144.18"
'enter dns server values you want here
Dim dnsserver(4)
dnsserver(0) = "17.16.96.22"
dnsserver(1) = "17.17.148.21"
dnsserver(2) = "17.16.96.23"
dnsserver(3) = "17.17.148.22"
Const ForReading = 1, TemporaryFolder = 2
Set tfolder = fso.GetSpecialFolder(TemporaryFolder)
set WshNetwork = WScript.CreateObject("WScript.Network")
Set WshShell = WScript.CreateObject("WScript.Shell")
Set logit = fso.OpenTextFile(logfile,8, True)
' ck for reg .exe
'Main loop it does everything
Set fserver = fso.GetFile(servfile)
Set tsserver = fserver.OpenAsTextStream(1)
logit.writeline
logit.writeline
logit.writeline "starting run on " & now
Do While tsserver.AtEndOfStream <> True
strComputer = tsserver.readline
If reachable(strcomputer) Then
If ckadmin(strcomputer) Then
logit.writeline
logit.writeline
logit.writeline "doing " & strcomputer
wscript.echo "doing " & strcomputer
Set undoit = fso.OpenTextFile(wkdir & strComputer &
"_undo.bat",8, True)
Set doit = fso.OpenTextFile(wkdir & strComputer &
"_doit.bat",8, True)
osver= getos(strcomputer)
Select Case osver
Case " 2195"
wscript.echo "windows 2000 osver =" & osver
Case " 1381"
wscript.echo "windows NT 4 osver =" & osver
case " 2600"
wscript.echo "windows XP osver =" & osver
Case Else
wscript.echo "os version not supported osver
=" & osver
End Select
logit.writeline "finished " & strcomputer
wscript.echo "finsihed " & strcomputer
undoit.close
doit.close
Set doit = nothing
Set undoit = nothing
Else
logit.writeline
logit.writeline
logit.writeline "Do not have admin right to computer
please ck it===> " & strcomputer
wscript.echo "Do not have admin right to computer
please ck it===> " & strcomputer
End If
Else
logit.writeline
logit.writeline
logit.writeline "This computer was not available please ck
it===> " & strcomputer
wscript.echo "This computer was not available please ck it
===>" & strcomputer
End If
loop
'clean up
logit.close
tsserver.close
Set tsserver = nothing
Set fserver = nothing
Set logit = nothing
Set fso = nothing
Set WshShell = nothing
set WshNetwork = nothing
Set tfolder = nothing
'gets current wins info
Public function winsinfo (byref strComputer)
'wscript.echo strComputer
cmdtorun = "cmd /c REG query \\" & strComputer &
"\HKLM\SYSTEM\CurrentControlSet\Services\NetBT\Parameters\Interfaces /s >" &
wkdir & strComputer & "_wins.old"
WshShell.run cmdtorun,1,true
winsinfo = wkdir & strComputer & "_wins.old"
end function
'this is where it reads the wins file sends the info to rewins to change the
values
Public Sub findwins(winfile,byref strComputer)
'wscript.echo winfile
Set fwins = fso.GetFile(winfile)
Set tswins = fwins.OpenAsTextStream(1)
Do while tswins.AtEndOfStream <> True
winline=tswins.readline
'wscript.echo winline &" =winline"
If
InStr(1,winline,"HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\NetBT\Parameters\Interfaces\Tcpip_",1)
> 0 Then
interface= Replace(winline,"HKEY_LOCAL_MACHINE","HKLM",1,-1,1)
'wscript.echo interface
end if
If InStr(1, winline,"NameServerList REG_MULTI_SZ",1)>0 And InStr(1,
winline,"DhcpNameServerList REG_MULTI_SZ",1)=0 Then
owinss= Split(winline," ", -1, 1)
'wscript.echo "owinns = " & owinss(2)
If owinss(2)= "\0" Or owinss(2)= "\0\0" Then
Else
logit.writeline vbTab& "WINS entry for
interface " & interface
logit.writeline vbtab& vbTab& " before WINS
change is " & vbTab& Replace(owinss(2), "\0", vbCrLf& vbtab& vbTab& vbtab&
vbtab& vbTab)
undoit.writeline "reg add \\" & strcomputer &
"\" & interface & " /v NameServerList /t REG_MULTI_SZ /f /d " &
Left(owinss(2),Len(owinss(2))-4 )
'wscript.echo interface
nwinns=rewins(owinss(2))
'wscript.echo "reg add \\" & strcomputer & "\"
& interface & " /v NameServerList /t REG_MULTI_SZ /f /d " & rewins (owinss(2))
doit.writeline "reg add \\" & strcomputer & "\"
& interface & " /v NameServerList /t REG_MULTI_SZ /f /d " & rewins (owinss(2))
'WshShell.run cmdtorun,1,true
logit.writeline vbtab& vbTab& " after WINS
change is " & vbTab& Replace(nwinns, "\0",vbCrLf& vbtab& vbTab& vbtab& vbtab&
vbTab)
End If
End If
Loop
tswins.close
Set tswins = nothing
Set fwins = nothing
End Sub
'changes the wins values and adds if necessary
Function rewins (owinns)
owinns = Left(owinns,len(owinns)-2)
'wscript.echo owinns
For rsnum = 0 To ubound(owinsserver)-1
'wscript.echo "doin owins = " & owinsserver(rsnum)
If InStr(1,owinns ,owinsserver(rsnum),1) And Not
owinsserver(rsnum)= "" Then
'wscript.echo "doin replace wins = " &
owinsserver(rsnum)
owinns = Replace(owinns, owinsserver(rsnum),
nwinsserver(rsnum))
Else
If InStr(1,owinns ,nwinsserver(rsnum),1) Then
Else
owinns = owinns & nwinsserver(rsnum) & "\0"
End If
End If
'wscript.echo owinns
Next
rewins=nodupwins(owinns & "\0")
'wscript.echo "rewins= " & rewins
End Function
'removes duplicate entries
Function nodupwins (valstr)
'wscript.echo "dodupwins(valstr) = " & valstr
entries=Split(valstr,"\0", -1, 1)
nodup = entries(0)
'wscript.echo ubound(entries)
For entrnum = 1 To ubound(entries)-1
If InStr(1,nodup,entries(entrnum), 1)=0 Then
nodup = nodup & "\0" & entries(entrnum)
End If
next
nodupwins = nodup
End Function
' get dns server info
Public function dnsinfo (byref strComputer)
'wscript.echo strComputer
cmdtorun = "cmd /c REG query \\" & strComputer &
"\HKLM\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Interfaces /s >" &
wkdir & strComputer & "_dns.old"
WshShell.run cmdtorun,1,true
dnsinfo = wkdir & strComputer & "_dns.old"
end function
'changes the dns info
Public Sub finddns(dnfile,byref strComputer)
'wscript.echo dnfile
Set fdns = fso.GetFile(dnfile)
Set tsdns = fdns.OpenAsTextStream(1)
Do while tsdns.AtEndOfStream <> True
dnline=tsdns.readline
'wscript.echo dnline
If
InStr(1,dnline,"HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Interfaces\",1)
> 0 Then
interface= Replace(dnline,"HKEY_LOCAL_MACHINE","HKLM")
'wscript.echo "interface = " & interface
end if
If InStr(1,dnline ,"IPAddress REG_MULTI_SZ" ,1) Then
ipdns = Split(dnline, " ", -1, 1)
Else
End If
If InStr(1,dnline ,"IPAddress REG_MULTI_SZ" ,1) Then
ipadd = Split(dnline, " ", -1, 1)
Else
End If
If InStr(1,dnline ,"SubnetMask REG_MULTI_SZ " ,1) Then
SUBNET = Split(dnline, " ", -1, 1)
Else
End If
If InStr(1,dnline ,"DefaultGateway REG_MULTI_SZ" ,1) Then
ROUTER = Split(dnline, " ", -1, 1)
Else
End If
If InStr(1,dnline,"NameServer REG_SZ",1)>0 And
InStr(1,dnline,"DhcpNameServer REG_SZ",1)=0 And
InStr(1,dnline,"127.0.0.1",1)=0Then
If dnline = " NameServer REG_SZ " Then
Else
'wscript.echo "name dnline= " &dnline
odnss= Split(dnline," ", -1, 1)
'wscript.echo "odnns = " & odnss(2)
logit.writeline vbTab& "dns entry for interface
" & interface
logit.writeline
ipadd(2)=Replace(ipadd(2), "\0", " ")
logit.writeline vbTab& vbTab& "IP address is "
& ipadd(2)
logit.writeline vbTab& vbTab& "Subnet mask is "
& Replace(SUBNET(2), "\0", " ")
logit.writeline vbTab& vbTab& "Default Gateway
is " & Replace(ROUTER(2), "\0", " ")
logit.writeline
logit.writeline vbtab& vbTab& " before DNS
change is " & vbTab& Replace(odnss(2), ",", vbCrLf& vbtab& vbTab& vbtab& vbtab&
vbTab)
undoit.writeline "reg add \\" & strcomputer &
"\" & interface & " /v NameServer /t REG_SZ /f /d " & odnss(2)
logit.writeline
logit.writeline
If InStr(1,ipadd(2),"0.0.0.0",1) Then
odnss(2)= ""
Else
For dnum = 0 To UBound(dnsserver)
If
InStr(1,odnss(2),dnsserver(dnum),1) > 0 Then
Else
'wscript.echo "adding " &
dnsserver(dnum)& " to " & odnss(2)
odnss(2) = odnss(2) & "," &
dnsserver(dnum)
End If
Next
wscript.echo UCASE(left(strcomputer,2 ))
If UCASE(left(strcomputer,2 ))="DC" Or
UCASE(left(strcomputer,2 ))="BH" Then
odnss(2) = Trim(ipadd(2)) &
"," &odnss(2)
End If
odnss(2)=nodupdns(odnss(2))
End If
logit.writeline vbtab& vbTab& " after DNS
change is " & vbTab& Replace(odnss(2), ",", vbCrLf& vbtab& vbTab& vbtab& vbtab&
vbTab)
logit.writeline
'wscript.echo "interface = " & interface
doit.writeline "reg add \\" & strcomputer & "\"
& interface & " /v NameServer /t REG_SZ /f /d " & odnss(2)
End If
End If
Loop
tsdns.close
Set tsdns = nothing
Set fdns = nothing
End Sub
'remove duplicate entries
Function nodupdns (valstr)
entries=Split(valstr,",", -1, 1)
nodup = entries(0)
'wscript.echo ubound(entries)
For entrnum = 1 To ubound(entries)
If InStr(1,nodup,entries(entrnum), 1)=0 Then
nodup = nodup & "," & entries(entrnum)
End If
next
nodupdns=nodup
End Function
' ck to see if the server is avalaible
function reachable(HostName)
reachable = false
tname = fso.GetTempName
TempFile = tfolder & tname
'-w 100000 is 5 mins worth of timeout to cope with establishing a dialup
wshShell.run "cmd /c ping -n 3 -w 1000 " & HostName & ">"
&TempFile,0,true
set results = fso.GetFile(TempFile)
set ts = results.OpenAsTextStream(ForReading)
do while ts.AtEndOfStream <> True
retString = ts.ReadLine
if instr(retString, "Reply")>0 then
reachable = true
exit do
end if
loop
ts.Close
results.delete
end function
Function ckadmin (machine)
If fso.DriveExists("z:") Then
WshNetwork.RemoveNetworkDrive "Z:",true
Else
end if
On Error resume next
WshNetwork.MapNetworkDrive "Z:", "\\" & machine& "\admin$"
If CStr(Err.Number) = 0 Then
ckadmin = true
Else
ckadmin =false
End If
WshNetwork.RemoveNetworkDrive "Z:",true
On Error GoTo 0
End Function
Public function getos (byref strComputer)
'wscript.echo strComputer
tname = fso.GetTempName
TempFile = tfolder & tname
wscript.echo "REG query " & chr(34) & "\\" & strComputer &
"\HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion" & chr(34) &" /v
CurrentBuildNumber > " &tempfile
cmdtorun = "cmd /c REG query " & chr(34) & "\\" & strComputer &
"\HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion" & chr(34) &" /v
CurrentBuildNumber > " & tempfile
WshShell.run cmdtorun,1,true
wscript.echo tempfile
set results = fso.GetFile(TempFile)
set ts = results.OpenAsTextStream(ForReading)
do while ts.AtEndOfStream <> True
retString = ts.ReadLine
wscript.echo retstring
if instr(1,retString, "REG_SZ",1)>0 then
ossplit = Split(retString, "REG_SZ", -1, 1)
getos = ossplit(1)
exit do
end if
loop
ts.Close
results.delete
wscript.echo getos
end function