KB5000802 BSOD bug - fix printers

Questions about WAPT Packaging / Requests and help regarding Wapt packages.
Forum Rules
Community Forum Rules
* English support on www.reddit.com/r/wapt
* French community support is available on this forum
* Please prefix the topic title with [RESOLVED] if it is resolved.
* Please do not edit a topic that is tagged [RESOLVED]. Open a new topic referencing the old one.
* Specify the installed WAPT version, full version, and build number (2.2.1.11957 / 2.2.2.12337 / etc.) as well as the Enterprise/Discovery edition.
* Versions 1.8.2 and earlier are no longer supported. The only questions accepted regarding version 1.8.2 are related to upgrading to a supported version (2.1, 2.2, etc.).
* Specify the server OS (Linux/Windows) and version (Debian Buster/Bullseye - CentOS 7 - Windows Server 2012/2016/2019).
* Specify the OS of the administration/package creation machine and the machine with the problematic agent, if applicable (Windows 7/10/11/Debian 11/etc.).
* Avoid asking multiple questions when opening a topic, otherwise it may be ignored. If there are multiple topics, open separate topics, preferably one after the other and not all at the same time (i.e., do not spam the forum).
* Include code snippets, screenshots, and other images directly in the post. Links to Pastebin, Bitly, and other third-party sites will be systematically removed.
* As with any community forum, support is provided voluntarily by members. If you require commercial support, you can contact Tranquil IT's sales department at 02.40.97.57.55
Locked
nliaudat
Messages: 29
Registration: August 8, 2019 - 8:31 AM

March 15, 2021 - 10:59

wapt package to fix printers bug introduced in KB5000802:
#https://www.windowslatest.com/2021/03/1 ... ch-update/

Code: Select all


##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)
nliaudat
Messages: 29
Registration: August 8, 2019 - 8:31 AM

March 16, 2021 - 10:06

Update after MS fix:

Code: Select all

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"
Locked