[Resolved] Changing machine network settings

Questions about WAPT Packaging / Requests and help regarding Wapt packages.
Forum Rules
Community Forum Rules
* English support on www.reddit.com/r/wapt
* French community support is available on this forum
* Please prefix the topic title with [RESOLVED] if it is resolved.
* Please do not edit a topic that is tagged [RESOLVED]. Open a new topic referencing the old one.
* Specify the installed WAPT version, full version, and build number (2.2.1.11957 / 2.2.2.12337 / etc.) as well as the Enterprise/Discovery edition.
* Versions 1.8.2 and earlier are no longer supported. The only questions accepted regarding version 1.8.2 are related to upgrading to a supported version (2.1, 2.2, etc.).
* Specify the server OS (Linux/Windows) and version (Debian Buster/Bullseye - CentOS 7 - Windows Server 2012/2016/2019).
* Specify the OS of the administration/package creation machine and the machine with the problematic agent, if applicable (Windows 7/10/11/Debian 11/etc.).
* Avoid asking multiple questions when opening a topic, otherwise it may be ignored. If there are multiple topics, open separate topics, preferably one after the other and not all at the same time (i.e., do not spam the forum).
* Include code snippets, screenshots, and other images directly in the post. Links to Pastebin, Bitly, and other third-party sites will be systematically removed.
* As with any community forum, support is provided voluntarily by members. If you require commercial support, you can contact Tranquil IT's sales department at 02.40.97.57.55
Locked
Gaelds
Messages: 254
Registration: Nov 22, 2015 - 08:37

August 20, 2019 - 11:19

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?
Last edited by gaelds on August 21, 2019 - 08:28, edited 1 time.
User avatar
sfonteneau
WAPT Expert
Messages: 2318
Registered: July 10, 2014 - 11:52 PM
Contact :

August 20, 2019 - 1:41 PM

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)
Gaelds
Messages: 254
Registration: Nov 22, 2015 - 08:37

August 21, 2019 - 08:28

Great, thank you very much!
Gaelds
Messages: 254
Registration: Nov 22, 2015 - 08:37

November 4, 2019 - 11:17

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.
Locked