neg604
(Fresh Scripter)
2003-09-28 08:56 AM
Set DNS Search Order

Am trying to change DNS search order

$strComputer = "."
$objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\"+$strComputer+"\root\cimv2")
$DNSAdapterSet = $objWMIService.ExecQuery("Select * from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE AND Description<>'PPP Adapter.' AND Description<>'Windows NT Remote Access WAN Wrapper'")
Dim $DNSip[4]
$DNSip[1] = '157.54.164.1'
$DNSip[2] = '157.54.164.2'
$DNSip[3] = '157.54.164.3'
$DNSip[4] = '157.54.164.4'


For Each $DNSAdapter In $DNSAdapterSet

$result = $DNSAdapter.SetDNSServerSearchOrder($DNSip)

If $result = 0
$null = MessageBox(@SERROR+"["+$result+"]", $DNSAdapter.IPAddress(0), 16)
Else
$null = MessageBox("IP Change failed."+" "+$result, $DNSAdapter.IPAddress(0), 16)
EndIf
Next

and i get COM exception error "SetDNSServerSearchOrder" (SWbemObject - Type mismatch
) [-2147352567/80020009]

Any ideas?

(This Board is just wonderfull)


LonkeroAdministrator
(KiX Master Guru)
2003-09-28 09:09 AM
Re: Set DNS Search Order

wonderfull board?
well said after one post [Big Grin]

anyway, you are feeding it an kixtart array, thus it cries, I bet.

what you really should feed to it?


neg604
(Fresh Scripter)
2003-09-28 09:17 AM
Re: Set DNS Search Order

Please look at the following address.....
Am thinking that the function SETDNSSERVERSEARCH ORDER waits for an array.But did not accepts either a string.

http://msdn.microsoft.com/library/en-us/wmisdk/wmi/setdnsserversearchorder_method_in_class_win32_networkadapterconfiguration.asp?frame=true

I have make only one post but am reading other posts for about 2 years.


LonkeroAdministrator
(KiX Master Guru)
2003-09-28 09:24 AM
Re: Set DNS Search Order

did you try with:
code:
Dim $DNSip=
'157.54.164.1 or '+
'157.54.164.2 or '+
'157.54.164.3 or '+
'157.54.164.4'



neg604
(Fresh Scripter)
2003-09-28 09:29 AM
Re: Set DNS Search Order

same error

i try also one ip only and i take also the same message


neg604
(Fresh Scripter)
2003-09-28 09:32 AM
Re: Set DNS Search Order

if i try to change (with another function) the
current domain suffix (that expects string) the change takes effect immediatly.

The "SetDNSServerSearchOrder" expects some specific type of input i think that after many many test can't find.


LonkeroAdministrator
(KiX Master Guru)
2003-09-28 10:35 AM
Re: Set DNS Search Order

well, re-read the page:
quote:

uint32 SetDNSServerSearchOrder(
string DNSServerSearchOrder[]
);

string can't be anything funky.


LonkeroAdministrator
(KiX Master Guru)
2003-09-28 10:46 AM
Re: Set DNS Search Order

ok, I found a proper way for methods.
wait a sec will write test script.


LonkeroAdministrator
(KiX Master Guru)
2003-09-28 11:05 AM
Re: Set DNS Search Order

before I do that and change my own DNS settings, why you don't change the settings with kix without com?

LonkeroAdministrator
(KiX Master Guru)
2003-09-28 11:06 AM
Re: Set DNS Search Order

here is code by sealeopard that can do other shit too:
http://www.kixtart.org/board/ultimatebb.php?ubb=get_topic;f=12;t=000148


neg604
(Fresh Scripter)
2003-09-28 11:07 AM
Re: Set DNS Search Order

be more specific (you mean with registry key?)

LonkeroAdministrator
(KiX Master Guru)
2003-09-28 11:18 AM
Re: Set DNS Search Order

not sure how specific I should be.
I can't start explaining the code, that would take 2 hours.
but, indeed it uses registry.
and it's not the simpliest UDF's I've seen.

JENS, you there?

what more info about it you want?


neg604
(Fresh Scripter)
2003-09-28 11:30 AM
Re: Set DNS Search Order

the "be more specific " goes to "before I do that and change my own DNS settings, why you don't change the settings with kix without com?" and not to UDF.

Are you a little suspicious about me. You think that am newbee and i want to ask you how can i modify registry?(reminds me microsoft "modify at your own risk")

My first question is about WMI method. Thanks for your try.I like short code is more simple to support my 2500 users with wmi functions than with one UDF with 2 pages of code.

Thanks ,


LonkeroAdministrator
(KiX Master Guru)
2003-09-28 11:47 AM
Re: Set DNS Search Order

ja, that UDF is sad show.
it probably would be just some lines for this task if someone else would have written it [Wink]

anyway, the WMI way I have partly generated.
I was able to lock myself offline with this:
$objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
$DNSAdapterSet = $objWMIService.ExecQuery("Select * from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE AND Description<>'PPP Adapter.' AND Description<>'Windows NT Remote Access WAN Wrapper'")

For Each $DNSAdapter In $DNSAdapterSet
$method = $DNSAdapter.Methods_.Item("SetDNSServerSearchOrder")
$inParam = $method.inParameters.SpawnInstance_()
; INPARAM property needed here.
$outParam = $DNSAdapter.ExecMethod_("SetDNSServerSearchOrder",$inParam)
next


dunno what inparam property I should put there.
anyway, my ironic note about the UDF (which you understood to point to registry stuff in it) was a pointer for you to try descripe a little more specific question [Wink]


Yiannis
(Lurker)
2003-09-29 12:09 AM
Re: Set DNS Search Order

finaly i find my proper username for this board

Les
(KiX Master)
2003-09-28 06:35 PM
Re: Set DNS Search Order

Yiannis,
Just how does this information you shared with us relate to this thread? Please refer to the board etiquette... in paticular, section I.

Topic: ABC's of KiXtart board etiquette and message to new forum users


Sealeopard
(KiX Master)
2003-09-29 02:58 AM
Re: Set DNS Search Order

One of the problems in the initial code is that KiXtart arrays start with index 0, however, there's no IP address assigned to index 0.

Yiannis
(Lurker)
2003-09-29 08:52 AM
Re: Set DNS Search Order

sealeopard - You've right about index. I modify the script but same error.(but i thing you know that already)

Yiannis
(Lurker)
2003-09-29 09:38 AM
Re: Set DNS Search Order

Something wrong must be on arrays of kix.Or something wrong with my mind.Whatever here are
one windows scripting host script i found (seems to be correct)

sNameSpace = "root/CIMV2"
sTargetClass = "Win32_NetworkAdapterConfiguration"
sClass = "Win32_NetworkAdapter"
sProperty1 = "AdapterType"
sValue1 = "Ethernet 802.3"
sProperty2 = "NetConnectionStatus"
iValue2 = 2

sComputer = "SWYNKPC0001"
sPriWINS = "1.2.3.4"
sSecWINS = "1.2.4.3"
aDNSServers = Array("1.2.2.1","1.2.3.5")
sDNSDomain = "swynk.com"
iNetBIOS = 1

sWQLQuery = "SELECT * FROM " & sClass & " WHERE " & sProperty1 & "=" & Chr(34) & sValue1 & Chr(34) & _
" AND " & sProperty2 & "=" & iValue2

Set cInstances = GetObject("winmgmts:{impersonationLevel=impersonate}//" & _
sComputer & "/" & sNameSpace).ExecQuery(sWQLQuery, "WQL")

For Each oInstance In cInstances
Set cAssociators = oInstance.Associators_(,sTargetClass)
For Each oAssociator In cAssociators
Set oMethod = oAssociator.Methods_("SetWINSServer")
Set oInParam = oMethod.InParameters.SpawnInstance_()
oInParam.WINSPrimaryServer = sPriWINS
oInParam.WINSSecondaryServer = sSecWINS
Set oOutParam = oAssociator.ExecMethod_("SetWINSServer", oInParam)

If oOutParam.returnValue = 0 Then
WScript.Echo UCase("SetWINSServer") & " method completed successfully"
Else
WScript.Echo UCase("SetWINSServer") & " method failed. Error Number " & oOutParam.returnValue
End If

Set oMethod = oAssociator.Methods_("SetDNSServerSearchOrder")
Set oInParam = oMethod.InParameters.SpawnInstance_()
oInParam.DNSServerSearchOrder = aDNSServers
Set oOutParam = oAssociator.ExecMethod_("SetDNSServerSearchOrder", oInParam)

If oOutParam.returnValue = 0 Then
WScript.Echo UCase("SetDNSServerSearchOrder") & " method completed successfully"
Else
WScript.Echo UCase("SetDNSServerSearchOrder") & " method failed. Error Number " & oOutParam.returnValue
End If

Set oMethod = oAssociator.Methods_("SetDNSDomain")
Set oInParam = oMethod.InParameters.SpawnInstance_()
oInParam.DNSDomain = sDNSDomain
Set oOutParam = oAssociator.ExecMethod_("SetDNSDomain", oInParam)

If oOutParam.returnValue = 0 Then
WScript.Echo UCase("SetDNSDomain") & " method completed successfully"
Else
WScript.Echo UCase("SetDNSDomain") & " method failed. Error Number " & oOutParam.returnValue
End If

Set oMethod = oAssociator.Methods_("SetTCPIPNetBIOS")
Set oInParam = oMethod.InParameters.SpawnInstance_()
oInParam.TcpipNetBIOSOptions = iNetBIOS
Set oOutParam = oAssociator.ExecMethod_("SetTCPIPNetBIOS", oInParam)

If oOutParam.returnValue = 0 Then
WScript.Echo UCase("SetTCPIPNetBIOS") & " method completed successfully"
Else
WScript.Echo UCase("SetTCPIPNetBIOS") & " method failed. Error Number " & oOutParam.returnValue
End If

Next
Next

(http://www.serverwatch.com/tutorials/article.php/1556311)

y can not do the same with kix???????????


LonkeroAdministrator
(KiX Master Guru)
2003-09-29 11:15 PM
Re: Set DNS Search Order

ok, looking at the codes you posted, my code does not need nothing else than the line I said it lacked.
$objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
$DNSAdapterSet = $objWMIService.ExecQuery("Select * from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE AND Description<>'PPP Adapter.' AND Description<>'Windows NT Remote Access WAN Wrapper'")

For Each $DNSAdapter In $DNSAdapterSet
$method = $DNSAdapter.Methods_.Item("SetDNSServerSearchOrder")
$inParam = $method.inParameters.SpawnInstance_()
$inParam.SetDNSServerSearchOrder="192.168.124.30","114.168.124.30"
$outParam = $DNSAdapter.ExecMethod_("SetDNSServerSearchOrder",$inParam)
$outParam.returnvalue ?
next


get $ exit 0


but, as you say, something is screwed.
it gives returnvalue of 0, thus it should work but indeed it removes all my servers [Big Grin]


Sealeopard
(KiX Master)
2003-09-30 04:31 PM
Re: Set DNS Search Order

Have you tried it with just one IP address?

LonkeroAdministrator
(KiX Master Guru)
2003-09-30 10:33 PM
Re: Set DNS Search Order

not sure did you ask me, but yes.
return code success and all dns-servers removed.