Setting DNS using win32com

Nacho ringogarcia at
Tue Feb 10 05:03:09 EST 2009

I am trying to make a small python application to change DNS servers
in a small LAN.

I am trying this code but I don't manage it to work, I only get the
values removed.

My code is this:

import win32com.client

objWMIService = win32com.client.GetObject("winmgmts:
{impersonationLevel=impersonate}!\\\\" + strComputer + "\\root\
nicList = objWMIService.ExecQuery("SELECT * FROM
Win32_NetworkAdapterConfiguration WHERE IPEnabled = True")

for nic in nicList:
    nic.DNSServerSearchOrder = (u'', u'')

nic.SetDNSServerSearchOrder returns 0 so it is supposed to have been
done correctly, but no DNS Server is found in the Network Properties.

I don't know what I am doing wrong so any hint or any documentation
about this would be appreciated.

Thank you by now.

More information about the Python-list mailing list