Page 1 sur 1

Utilisation de la class WaptWUA dans un script

Publié : 03 juil. 2026 - 11:26
par tux
Bonjour,

J'ai un script d'audit qui effectue un certain nombre d'opérations pendant une plage horaire, la nuit.
Une partie de ce script gère les mises à jour de Windows.

Nous venons d'effectuer la mise à jour (version 2.6.1.17384) et mon script ne fonctionne plus.
L'objectif est de faire la même chose qu'un « wapt-get waptwua-install » sans tâche planifiée.

Voici la portion de code qui me pose problème :

Code : Tout sélectionner

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

def audit():
	with EnsureWUAUServRunning():
            wua_client = WaptWUA(WAPT)
            wua_client.install_updates()
Voici l'erreur que j'obtiens :

Code : Tout sélectionner

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)>:
Pouvez-vous m'aider à adapter ce script?

Re: Utilisation de la class WaptWUA dans un script

Publié : 03 juil. 2026 - 16:35
par htouvet
Ah... peut être une régression

Pouvez-vous essayer le script en ajoutant un pythoncom.CoInitialize()

Code : Tout sélectionner

# -*- 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()

Re: Utilisation de la class WaptWUA dans un script

Publié : 03 juil. 2026 - 17:03
par tux
J'ai une erreur différente :

Code : Tout sélectionner

Exception at 7343A590: EAccessViolation:
Access violation.

Re: Utilisation de la class WaptWUA dans un script

Publié : 03 juil. 2026 - 18:59
par htouvet
Vous êtes bien sur la dernière 2.6.1.17834 ?
J'ai fait un test mais n'ai pas reproduit la violation d'accès.
Mais souvent ces erreurs "Access violation" sont dépendantes de l'état précédent de la mémoire.

Re: Utilisation de la class WaptWUA dans un script

Publié : 06 juil. 2026 - 09:08
par tux
Bonjour,

Oui, je suis bien la version 2.6.1.17834, je n'ai pas encore mis à jour ma signature.
Je viens de tester ce matin sur mon poste fraîchement démarré, et j'obtiens le même problème.

L'appel à la fonction pythoncom.CoUninitialize() peut-il avoir un impact sur PyScripter ?

Code : Tout sélectionner

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 ***
>>>