Рассматриваемая функция:
Код: Выделить всё
def scan_for_updates():
"""
Scans for available Windows updates using the Windows Update Agent API.
"""
try:
pythoncom.CoInitialize()
# Create a session with the Windows Update Agent
update_session = win32com.client.Dispatch("Microsoft.Update.Session")
update_searcher = update_session.CreateUpdateSearcher()
# Search for updates that are not installed
search_result = update_searcher.Search("IsInstalled=0")
if search_result.Updates.Count == 0:
print("No updates available.")
return []
displayed_updates = [] # List to store non-driver updates
print("Available Updates:\n")
for update in search_result.Updates:
# Skip updates in the "Drivers" category
if any(category.Name == "Drivers" for category in update.Categories):
continue
# Extract update details
title = update.Title
description = getattr(update, "Description", "No description available")
kb_numbers = ", ".join([f"{kb}" for kb in update.KBArticleIDs]) if update.KBArticleIDs else "N/A"
file_size_mb = int(update.MaxDownloadSize) / (1024 * 1024) if hasattr(update, "MaxDownloadSize") else 0
# Parse and format LastDeploymentChangeTime
deployment_date = "N/A"
if hasattr(update, "LastDeploymentChangeTime"):
try:
deployment_date = datetime.fromisoformat(str(update.LastDeploymentChangeTime)).strftime("%d-%m-%y")
except ValueError:
deployment_date = "Invalid Date"
# Add the update details to the list
displayed_updates.append({
"Title": title,
"Description": description,
"KB Number(s)": kb_numbers,
"File Size (MB)": file_size_mb,
"Last Deployment Date": deployment_date
})
# Display the update details
print(f"Title: {title}")
print(f"Description: {description}")
print(f"KB Number(s): {kb_numbers}")
print(f"File Size: {file_size_mb:.2f} MB")
print(f"Last Deployment Date: {deployment_date}")
print("-" * 50)
# Display the total number of non-driver updates
print(f"\nTotal Updates Found (excluding Drivers): {len(displayed_updates)}")
return displayed_updates
except Exception as e:
print(f"An error occurred while scanning for updates: {e}")
return []
finally:
pythoncom.CoUninitialize()
Я пытался явно запустить функцию в отдельном потоке, это не дало никаких различий.
Явное регистрация не помогла выявить проблему. Если я объединим создание CSV и сканирование обновлений в одну функцию, я получу желаемый результат, но он по-прежнему блокирует любые инструкции, происходящие вне функции, что не позволяет мне отправить ответ на мой сервер для перехода к следующему устройству в списке сканирования.
Подробнее здесь: https://stackoverflow.com/questions/793 ... ing-a-prob
Мобильная версия