Using the WaptWUA class in a script

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
Answer
tux
Messages: 65
Registration: Sep 05, 2023 - 09:44

July 3, 2026 - 11:26

Good morning,

I have an audit script that performs a number of operations during a time range, at night.
Part of this script manages Windows updates.

We have just performed the update (version 2.6.1.17384) and my script no longer works.
The goal is to do the same thing as a "wapt-get waptwua-install" without a scheduled task.

Here is the section of code that is causing me problems:

Code: Select all

# -*- coding: utf-8 -*-
from setuphelpers import *
from waptwua.client import WaptWUA

def audit():
	with EnsureWUAUServRunning():
            wua_client = WaptWUA(WAPT)
            wua_client.install_updates()
Here is the error I am getting:

Code: Select all

2026-07-03 10:53:13,522 ERROR ERROR installing update: 0x800401f0 : CoInitialize n’a pas été appelé.
2026-07-03 10:53:13,768 CRITICAL Unable to build status data for key host_networking: x_wmi_uninitialised_thread("WMI returned a syntax error: you're probably running inside a thread without first calling pythoncom.CoInitialize[Ex]")
2026-07-03 10:53:13,773 CRITICAL WMI is broken on this computer. See https://techcommunity.microsoft.com/t5/ask-the-performance-team/wmi-rebuilding-the-wmi-repository/ba-p/373846 : x_wmi_uninitialised_thread: <x_wmi: WMI returned a syntax error: you're probably running inside a thread without first calling pythoncom.CoInitialize[Ex] (no underlying exception)>
[]
re-enabling wuauserv previous state: 0
2026-07-03 10:53:14,246 CRITICAL Fatal error in audit function: x_wmi_uninitialised_thread: <x_wmi: WMI returned a syntax error: you're probably running inside a thread without first calling pythoncom.CoInitialize[Ex] (no underlying exception)>:
Can you help me adapt this script?
Wapt Enterprise Edition 2.6.1.17765
WAPTConsole Enterprise on Windows
WAPT Server on Debian 12
User avatar
htouvet
WAPT Expert
Messages: 438
Registration: March 16, 2015 - 10:48
Contact :

July 3, 2026 - 4:35 PM

Ah... maybe a regression

Can you try the script by adding a pythoncom.CoInitialize()?

Code: Select all

# -*- coding: utf-8 -*-
from setuphelpers import *
from waptwua.client import WaptWUA
import pythoncom

def audit():
    try:
        pythoncom.CoInitialize()
    	with EnsureWUAUServRunning():
                wua_client = WaptWUA(WAPT)
                wua_client.install_updates()
    finally:
        pythoncom.CoUninitialize()
Tranquil IT
tux
Messages: 65
Registration: Sep 05, 2023 - 09:44

July 3, 2026 - 5:03 PM

I have a different error:

Code: Select all

Exception at 7343A590: EAccessViolation:
Access violation.
Wapt Enterprise Edition 2.6.1.17765
WAPTConsole Enterprise on Windows
WAPT Server on Debian 12
User avatar
htouvet
WAPT Expert
Messages: 438
Registration: March 16, 2015 - 10:48
Contact :

July 3, 2026 - 6:59 PM

Are you sure you're on the latest version, 2.6.1.17834?
I ran a test but couldn't reproduce the access violation.
However, these "Access violation" errors are often dependent on the previous memory state.
Tranquil IT
tux
Messages: 65
Registration: Sep 05, 2023 - 09:44

July 6, 2026 - 09:08

Good morning,

Yes, I am indeed on version 2.6.1.17834, I have not yet updated my signature.
I just tested it this morning on my newly started machine, and I'm getting the same problem.

Can calling the pythoncom.CoUninitialize() function have an impact on PyScripter?

Code: Select all

Scanning with windows updates rules:
{
 "direct_download":false,
 "default_allow":false,
 "include_potentially_superseded_updates":false,
 "filter":"Type='Software' or Type='Driver'",
 "download_scheduling":"12h",
 "install_scheduling":"6h",
 "install_delay":null,
 "postboot_delay":"10m",
 "user_locale":1033
}
Bypassing scan, no change since last successful scan
Exception at 728BA590: EAccessViolation:
Access violation.
>>> 
*** Remote Interpreter Reinitialized ***
>>> 
Wapt Enterprise Edition 2.6.1.17765
WAPTConsole Enterprise on Windows
WAPT Server on Debian 12
Answer