#https://www.windowslatest.com/2021/03/1 ... ch-update/
Code : Tout sélectionner
##https://www.windowslatest.com/2021/03/13/microsoft-working-on-a-fix-for-windows-10-bsod-march-update/
import ctypes
from ctypes.wintypes import BYTE, DWORD, LPCWSTR
printers = [
'KX DRIVER for Universal Printing',
'TASKalfa 4052ci',
'Kyocera TASKalfa 4052ci KX',
'Kyocera TASKalfa 3252ci KX',
'Kyocera TASKalfa 3252ci'
]
def install():
pass
winspool = ctypes.WinDLL('winspool.drv') # for EnumPrintersW
msvcrt = ctypes.cdll.msvcrt # for malloc, free
# Parameters: modify as you need. See MSDN for detail.
PRINTER_ENUM_LOCAL = 2
Name = None # ignored for PRINTER_ENUM_LOCAL
Level = 1 # or 2, 4, 5
class PRINTER_INFO_1(ctypes.Structure):
_fields_ = [
("Flags", DWORD),
("pDescription", LPCWSTR),
("pName", LPCWSTR),
("pComment", LPCWSTR),
]
# Invoke once with a NULL pointer to get buffer size.
info = ctypes.POINTER(BYTE)()
pcbNeeded = DWORD(0)
pcReturned = DWORD(0) # the number of PRINTER_INFO_1 structures retrieved
winspool.EnumPrintersW(PRINTER_ENUM_LOCAL, Name, Level, ctypes.byref(info), 0,
ctypes.byref(pcbNeeded), ctypes.byref(pcReturned))
bufsize = pcbNeeded.value
buffer = msvcrt.malloc(bufsize)
winspool.EnumPrintersW(PRINTER_ENUM_LOCAL, Name, Level, buffer, bufsize,
ctypes.byref(pcbNeeded), ctypes.byref(pcReturned))
info = ctypes.cast(buffer, ctypes.POINTER(PRINTER_INFO_1))
for i in range(pcReturned.value):
print info[i].pName, '=>', info[i].pDescription
if info[i].pName in printers:
#print('Enable direct print for kyocera')
#for printer in printers:
print(' Fix %s' % info[i].pName)
run_notfatal(r'rundll32 printui.dll,PrintUIEntry /Xs /n "%s" attributes +direct' % info[i].pName)
msvcrt.free(buffer)
def uninstall():
pass
# put here what to do when package is removed from host
# implicit context variables are WAPT, control, user, params, run
winspool = ctypes.WinDLL('winspool.drv') # for EnumPrintersW
msvcrt = ctypes.cdll.msvcrt # for malloc, free
# Parameters: modify as you need. See MSDN for detail.
PRINTER_ENUM_LOCAL = 2
Name = None # ignored for PRINTER_ENUM_LOCAL
Level = 1 # or 2, 4, 5
class PRINTER_INFO_1(ctypes.Structure):
_fields_ = [
("Flags", DWORD),
("pDescription", LPCWSTR),
("pName", LPCWSTR),
("pComment", LPCWSTR),
]
# Invoke once with a NULL pointer to get buffer size.
info = ctypes.POINTER(BYTE)()
pcbNeeded = DWORD(0)
pcReturned = DWORD(0) # the number of PRINTER_INFO_1 structures retrieved
winspool.EnumPrintersW(PRINTER_ENUM_LOCAL, Name, Level, ctypes.byref(info), 0,
ctypes.byref(pcbNeeded), ctypes.byref(pcReturned))
bufsize = pcbNeeded.value
buffer = msvcrt.malloc(bufsize)
winspool.EnumPrintersW(PRINTER_ENUM_LOCAL, Name, Level, buffer, bufsize,
ctypes.byref(pcbNeeded), ctypes.byref(pcReturned))
info = ctypes.cast(buffer, ctypes.POINTER(PRINTER_INFO_1))
for i in range(pcReturned.value):
print info[i].pName, '=>', info[i].pDescription
if info[i].pName in printers:
#print('Enable direct print for kyocera')
#for printer in printers:
print(' Fix %s' % info[i].pName)
run_notfatal(r'rundll32 printui.dll,PrintUIEntry /Xs /n "%s" attributes -direct' % info[i].pName)
msvcrt.free(buffer)