Page 1 of 1

[Resolved] Changing machine network settings

Published: August 20, 2019 - 11:19
by gaelds
Good morning,
I want to change the configuration of my machines to switch from a manual IP address to an IP address and DNS servers assigned by DHCP. I'm testing with this code:

Code: Select all

# -*- coding: utf-8 -*-
from setuphelpers import *
import wmi

def install():
    nic_configs = wmi.WMI().Win32_NetworkAdapterConfiguration(IPEnabled=True)
    nic = nic_configs[0]
    nic.EnableDHCP()
    nic.SetDNSServerSearchOrder([])
When I install the package on a randomly selected Windows 7 student PC, the manual DNS settings remain, only the IP address is set to automatic. But if I install the package via the command line, it works! Is there another method to make it work with console installation?

Re: Changing machine network settings

Published: August 20, 2019 - 1:41 PM
by sfonteneau
Attached is a code that works for us

Code: Select all

#!/usr/bin/python
# -*- coding: utf-8 -*-
from setuphelpers import *
import wmi
uninstallkey = []

def install():
    try:
        nic_configs = wmi.WMI().Win32_NetworkAdapterConfiguration(IPEnabled=True)
        if not nic_configs:
            raise Exception
    except Exception:
        print u"No network interface found. Exiting gracefully."
        exit(1)

    for nic in nic_configs:
        print u"Please wait..."
        print u"Using DHCP on interface '" + nic.description + "'"
        nic.EnableDHCP()
        nic.SetDynamicDNSRegistration()
        nic.EnableDHCP()
        run(u'ipconfig /renew', timeout=15)

Re: Changing machine network settings

Published: August 21, 2019 - 08:28
by gaelds
Great, thank you very much!

Re: [Resolved] Changing machine network settings

Published: November 4, 2019 - 11:17 AM
by gaelds
I finally took the time to test this code on a Windows 7 machine, but the package doesn't install correctly. Even after rebooting, the IP address is set to automatic, but the old DNS settings remain manual.

Here are the installation logs from the console:

Code: Select all

Please wait...Using DHCP on interface 'Realtek PCIe GBE Family Controller'Traceback (most recent call last):
  File "C:\wapt\common.py", line 3846, in install_wapt
    exitstatus = setup.install()
  File "c:\windows\temp\waptcnpcef\setup.py", line 22, in install
  File "C:\wapt\common.py", line 3625, in run
    return ensure_unicode(setuphelpers.run(*arg,pidlist=self.pidlist,**args))
  File "C:\wapt\setuphelpers.py", line 1046, in run
    raise TimeoutExpired(cmd,''.join(output),timeout)
TimeoutExpired: Command 'ipconfig /renew' timed out after 15 seconds with output ''\r\nConfiguration IP de Windows\r\n\r\n''
TimeoutExpired: Command 'ipconfig /renew' timed out after 15 seconds with output ''\r\nConfiguration IP de Windows\r\n\r\n''

If I delete the "ipconfig /renew" command, the package installs without error, but the DNS settings are not automatically reset.
If I replace the nic.SetDynamicDNSRegistration() command with nic.SetDNSServerSearchOrder(['172.16.80.13','172.16.80.14']), the DNS is indeed modified.
The command nic.SetDynamicDNSRegistration(FullDNSRegistrationEnabled=1) does not appear to work either.