The code fragments is the following:
arrSufixes = Array("Mydomain.com", "myotherdomain.com")
For Each oAdapter in colNetAdapters
errEnable = oAdapter.EnableStatic(arrIP, arrSubnet)
errDNS = oAdapter.SetDNSServerSearchOrder(arrDNS)
errDNS = oAdapter.SetDNSSuffixSearchOrder(arrSufixes)
If errEnable = 0 Then
WScript.Echo "The IP address has been changed."
Else
WScript.Echo "The IP address could not be changed."
End If
Next
From "SetDNSSuffixSearchOrder Method in Class Win32_NetworkAdapterConfiguration"
<qoute>
The SetDNSSuffixSearchOrder WMI class static method allows for the setting of
the suffix
search order as a array of elements. This is an instance-independent method call
that
applies across all adapters.
</qoute>
The error in your script, is that you use this SetDNSSuffixSearchOrder method on
the
instance. The doc above says "this is an instance-independent method ", that
means that
you need to use it on the class instead.
errDNS = oAdapter.SetDNSSuffixSearchOrder(arrSufixes)
you would need to use this instead
Set oClass = oWMI.Get(oAdapter.Path_.class)
errDNS = oClass.SetDNSSuffixSearchOrder(arrSufixes)
The same goes for EnableDNS method in class Win32_NetworkAdapterConfiguration:
http://msdn.microsoft.com/library/en-us/wmisdk/wmi/enabledns_method_in_class_win32_networkadapterconfiguration.asp
It is an instance-independent method call that applies across all adapters,
just like SetDNSSuffixSearchOrder.
Here is the complete code that might work better (Note: Air code, not tested!):
sNode = "." 'use "." for local machine
Set oWMI = GetObject("winmgmts://" & sNode)
' only select adapters where ipEnabled is true
sQuery = "Select * From Win32_NetworkAdapterConfiguration" _
& " where ipEnabled = true"
Set colNetAdapters = oWMI.ExecQuery(sQuery)
arrIP = ...
arrSubnet = ...
arrDNS = ...
arrSufixes = Array("Mydomain.com", "myotherdomain.com")
For Each oAdapter in colNetAdapters
errEnable = oAdapter.EnableStatic(arrIP, arrSubnet)
errDNS = oAdapter.SetDNSServerSearchOrder(arrDNS)
Set oClass = oWMI.Get(oAdapter.Path_.class)
errDNS = oClass.SetDNSSuffixSearchOrder(arrSufixes)
If errEnable = 0 Then
WScript.Echo "The IP address has been changed."
Else
WScript.Echo "The IP address could not be changed."
End If
Next
--
torgeir
Microsoft MVP Scripting and WMI
Porsgrunn Norway