fix: report known catalog conflicts before WMI startup
This commit is contained in:
1 parent
0ee24d7beb
commit
75612cd4da
4 files changed
+88
-17
No files matched your search
@@ -7,6 +7,42 @@ import sys
|
||||
import tempfile
|
||||
|
||||
|
||||
def snapshot_process_ids(name):
|
||||
"""Read executable names from the local process table without starting WMI."""
|
||||
import ctypes
|
||||
from ctypes import wintypes
|
||||
|
||||
class ProcessEntry(ctypes.Structure):
|
||||
_fields_ = [('size', wintypes.DWORD), ('usage', wintypes.DWORD), ('pid', wintypes.DWORD),
|
||||
('heap_id', ctypes.c_size_t), ('module_id', wintypes.DWORD), ('threads', wintypes.DWORD),
|
||||
('parent', wintypes.DWORD), ('priority', wintypes.LONG), ('flags', wintypes.DWORD),
|
||||
('name', wintypes.WCHAR * 260)]
|
||||
|
||||
kernel = ctypes.WinDLL('kernel32', use_last_error=True)
|
||||
kernel.CreateToolhelp32Snapshot.argtypes = [wintypes.DWORD, wintypes.DWORD]
|
||||
kernel.CreateToolhelp32Snapshot.restype = wintypes.HANDLE
|
||||
kernel.CloseHandle.argtypes = [wintypes.HANDLE]
|
||||
for step in (kernel.Process32FirstW, kernel.Process32NextW):
|
||||
step.argtypes = [wintypes.HANDLE, ctypes.POINTER(ProcessEntry)]
|
||||
step.restype = wintypes.BOOL
|
||||
handle = kernel.CreateToolhelp32Snapshot(2, 0) # TH32CS_SNAPPROCESS
|
||||
if handle == ctypes.c_void_p(-1).value:
|
||||
raise ctypes.WinError(ctypes.get_last_error())
|
||||
try:
|
||||
entry = ProcessEntry(size=ctypes.sizeof(ProcessEntry))
|
||||
found = []
|
||||
processing = kernel.Process32FirstW(handle, ctypes.byref(entry))
|
||||
while processing:
|
||||
if entry.name.casefold() == name.casefold():
|
||||
found.append(entry.pid)
|
||||
processing = kernel.Process32NextW(handle, ctypes.byref(entry))
|
||||
if ctypes.get_last_error() != 18: # ERROR_NO_MORE_FILES
|
||||
raise ctypes.WinError(ctypes.get_last_error())
|
||||
return found
|
||||
finally:
|
||||
kernel.CloseHandle(handle)
|
||||
|
||||
|
||||
def query_owners(names, *, timeout_seconds=10):
|
||||
names = tuple(names)
|
||||
if not names or any(not re.fullmatch(r'[\w.-]+\.exe', name, re.I) for name in names):
|
||||
|
||||
Reference in new issue
Block a user