I am using the following function in a HTA to change IP information on
Windows Server 2003 and Windows 2000 Servers. All the IP information
appears to change to the correct values. I can even open Windows
Explorer and see the Windows Domains and other servers on the network.
But I can not see this server that I have performed the change on from
other systems on the network. I can not ping this server either. The
only way to correct this is to simply make a manual modification to the
default gateway setting and save the modification. This immediately
corrects the issue. I do not have to change the default gateway, just
retype the last octet and click ok. From all the examples that I have
seen, this function should work just fine. I do not see what I am doing
wrong/different.
(Note: Watch for wrap)
Sub setTCPIP(strAdapter)
Dim oNetwork, Adapter, a_Pro_DNS, a_Pro_IP, a_Pro_Subnet,
a_Pro_GateWay, msg
Dim Pro_IP, Pro_Subnet, Pro_Gateway, Pro_DNS, retValue, strDNS,
a_DNS_Suffix
Dim oWMI, sQuery, oClass
Dim iRC, aRegKeys, sKeyName, sValue
a_Pro_IP = Array (document.body.all("pIP").innerText)
a_Pro_Subnet = Array (document.body.all("pSubNet").innerText)
a_Pro_Gateway = Array (document.body.all("pGW").innerText)
a_Gateway_Metric = Array(1)
a_DNS_Suffix = Split (document.body.all("Suffix").innerText, ",")
a_Pro_DNS = Split (document.body.all("pDNS").innerText + ","
+document.body.all("sDNS").innerText, ",")
a_WINS = document.body.all("WINS").innerText
Set oWMI = GetObject("winmgmts:\\.\root\cimv2")
sQuery = "Select * From Win32_NetworkAdapterConfiguration WHERE Index
= " & strAdapter
Set oNetwork = oWMI.Get("Win32_NetworkAdapterConfiguration")
retValue = oNetwork.EnableWINS(DNS_ENABLED_FOR_WINS_RESOLUTION,
USE_LMHOST_FILE,"","")
Set oNetwork = oWMI.ExecQuery(sQuery)
For Each Adapter in oNetwork
if not testing then
retValue = Adapter.EnableStatic(a_Pro_IP, a_Pro_Subnet)
if retValue = 0 then
document.body.all("Prompt").innerHTML="The IP address has been
changed."
elseif retValue = 1 then
document.body.all("Prompt").innerHTML="The IP address has been
changed, reboot needed"
else
document.body.all("Prompt").innerHTML="The IP address could not
be changed, error # " & retValue
end if
HTASleep 3
retValue = Adapter.SetGateways(a_Pro_Gateway, a_Gateway_Metric)
if retValue = 0 then
document.body.all("Prompt").innerHTML="The Gateway has been
changed."
elseif retValue = 1 then
document.body.all("Prompt").innerHTML="The Gateway has been
changed, reboot needed"
else
document.body.all("Prompt").innerHTML="The Gateway could not be
changed, error # " & retValue
end if
HTASleep 3
retValue = Adapter.SetDNSServerSearchOrder(a_Pro_DNS)
if retValue = 0 then
document.body.all("Prompt").innerHTML="The DNS Search Order has
been changed."
elseif retValue = 1 then
document.body.all("Prompt").innerHTML="The DNS Search Order has
been changed, reboot needed"
else
document.body.all("Prompt").innerHTML="The DNS Search Order
could not be changed, error # " & retValue
end if
HTASleep 3
retValue = Adapter.SetWINSServer(a_WINS,"")
if retValue = 0 then
document.body.all("Prompt").innerHTML="The WINS Server has been
changed."
elseif retValue = 1 then
document.body.all("Prompt").innerHTML="The WINS Server has been
changed, reboot needed"
else
document.body.all("Prompt").innerHTML="The WINS Server could
not be changed, error # " & retValue
end if
HTASleep 3
Set oClass = oWMI.Get(Adapter.Path_.class)
retValue = oClass.SetDNSSuffixSearchOrder(a_DNS_Suffix)
if retValue = 0 then
document.body.all("Prompt").innerHTML="The DNS Suffix Search
Order has been changed."
elseif retValue = 1 then
document.body.all("Prompt").innerHTML="The DNS Suffix Search
Order has been changed, reboot needed"
else
document.body.all("Prompt").innerHTML="The DNS Suffix Search
Order could not be changed, error # " & retValue
end if
HTASleep 3
end if
gmsg= Adapter.Description + vbcrlf + " has been configured for use
with the following values:" + vbcrlf + vbcrlf + _
"IP Address:" + chr(9) + chr(9) +
document.body.all("pIP").innerText + vbcrlf + _
"Subnet Mask:" + chr(9) + chr(9) +
document.body.all("pSubNet").innerText + vbcrlf + _
"Gateway:" + chr(9) + chr(9) + chr(9) +
document.body.all("pGW").innerText + vbcrlf + _
"DNS Search Order:" + chr(9) + chr(9) +
document.body.all("pDNS").innerText + ","
+document.body.all("sDNS").innerText + vbcrlf + _
"WINS Server(s):" + chr(9) + chr(9) +
document.body.all("WINS").innerText + vbcrlf + _
"DNS Suffix Search Order:" + chr(9) +
document.body.all("Suffix").innerText + vbcrlf + vbcrlf
Exit For
Next
End Sub
I have verified that the text that I am retrieving for the values are
correct and free from any invalid characters.
Any idea what I am missing here?
Thanks for any assistance,
B-Mann