Page 1 of 2 12>
Topic Options
#92994 - 2003-09-28 08:56 AM Set DNS Search Order
neg604 Offline
Fresh Scripter

Registered: 2003-09-28
Posts: 6
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)

Top
#92995 - 2003-09-28 09:09 AM Re: Set DNS Search Order
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
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?
_________________________
!

download KiXnet

Top
#92996 - 2003-09-28 09:17 AM Re: Set DNS Search Order
neg604 Offline
Fresh Scripter

Registered: 2003-09-28
Posts: 6
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.

Top
#92997 - 2003-09-28 09:24 AM Re: Set DNS Search Order
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
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'

_________________________
!

download KiXnet

Top
#92998 - 2003-09-28 09:29 AM Re: Set DNS Search Order
neg604 Offline
Fresh Scripter

Registered: 2003-09-28
Posts: 6
same error

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

Top
#92999 - 2003-09-28 09:32 AM Re: Set DNS Search Order
neg604 Offline
Fresh Scripter

Registered: 2003-09-28
Posts: 6
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.

Top
#93000 - 2003-09-28 10:35 AM Re: Set DNS Search Order
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
well, re-read the page:
quote:

uint32 SetDNSServerSearchOrder(
string DNSServerSearchOrder[]
);

string can't be anything funky.
_________________________
!

download KiXnet

Top
#93001 - 2003-09-28 10:46 AM Re: Set DNS Search Order
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
ok, I found a proper way for methods.
wait a sec will write test script.
_________________________
!

download KiXnet

Top
#93002 - 2003-09-28 11:05 AM Re: Set DNS Search Order
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
before I do that and change my own DNS settings, why you don't change the settings with kix without com?
_________________________
!

download KiXnet

Top
#93003 - 2003-09-28 11:06 AM Re: Set DNS Search Order
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
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
_________________________
!

download KiXnet

Top
#93004 - 2003-09-28 11:07 AM Re: Set DNS Search Order
neg604 Offline
Fresh Scripter

Registered: 2003-09-28
Posts: 6
be more specific (you mean with registry key?)
Top
#93005 - 2003-09-28 11:18 AM Re: Set DNS Search Order
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
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?
_________________________
!

download KiXnet

Top
#93006 - 2003-09-28 11:30 AM Re: Set DNS Search Order
neg604 Offline
Fresh Scripter

Registered: 2003-09-28
Posts: 6
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 ,

Top
#93007 - 2003-09-28 11:47 AM Re: Set DNS Search Order
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
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]
_________________________
!

download KiXnet

Top
#93008 - 2003-09-29 12:09 AM Re: Set DNS Search Order
Yiannis Offline
Lurker

Registered: 2002-09-06
Posts: 4
Loc: Athens
finaly i find my proper username for this board
Top
#93009 - 2003-09-28 06:35 PM Re: Set DNS Search Order
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
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
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#93010 - 2003-09-29 02:58 AM Re: Set DNS Search Order
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11164
Loc: Boston, MA, USA
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.
_________________________
There are two types of vessels, submarines and targets.

Top
#93011 - 2003-09-29 08:52 AM Re: Set DNS Search Order
Yiannis Offline
Lurker

Registered: 2002-09-06
Posts: 4
Loc: Athens
sealeopard - You've right about index. I modify the script but same error.(but i thing you know that already)
Top
#93012 - 2003-09-29 09:38 AM Re: Set DNS Search Order
Yiannis Offline
Lurker

Registered: 2002-09-06
Posts: 4
Loc: Athens
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???????????

Top
#93013 - 2003-09-29 11:15 PM Re: Set DNS Search Order
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
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]
_________________________
!

download KiXnet

Top
Page 1 of 2 12>


Moderator:  Shawn, ShaneEP, Ruud van Velsen, Arend_, Jochen, Radimus, Glenn Barnas, Allen, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 248 anonymous users online.
Newest Members
gespanntleuchten, DaveatAdvanced, Paulo_Alves, UsTaaa, xxJJxx
17864 Registered Users

Generated in 0.076 seconds in which 0.027 seconds were spent on a total of 13 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org