Page 1 sur 1

KB5000802 BSOD bug - fix printers

Posté : 15 mars 2021 - 10:59
par nliaudat
wapt package to fix printers bug introduced in KB5000802 :
#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)

Re: KB5000802 BSOD bug - fix printers

Posté : 16 mars 2021 - 10:06
par nliaudat
Update after MS fix :

Code : Tout sélectionner

def install():
print('Install kb5001567')
    #2359302 = WU_S_ALREADY_INSTALLED
    run('wusa.exe windows10.0-kb5001567-x64_e3c7e1cb6fa3857b5b0c8cf487e7e16213b1ea83.msu /quiet /norestart',accept_returncodes=[0,2359302])
    
    
def audit():
    print(run_notfatal(r'wmic qfe list | findstr 5001567'))


    return "OK"