human
Complete this python program:
def comports(available_only=True):
assistant
#Here is the Python program you requested.

    """This generator scans the device registry for com ports and yields
    (order, port, desc, hwid).  If available_only is true only return currently
    existing ports. Order is a helper to get sorted lists. it can be ignored
    otherwise.
    """
    flags = DIGCF_DEVICEINTERFACE
    if available_only:
        flags |= DIGCF_PRESENT
    g_hdi = SetupDiGetClassDevs(ctypes.byref(GUID_CLASS_COMPORT), None, NULL, flags)
    for dwIndex in range(256):
        did = SP_DEVICE_INTERFACE_DATA()
        did.cbSize = ctypes.sizeof(did)
        if (not SetupDiEnumDeviceInterfaces(g_hdi, None, ctypes.byref(GUID_CLASS_COMPORT), dwIndex, ctypes.byref(did))):
            if (ctypes.GetLastError() != ERROR_NO_MORE_ITEMS):
                raise ctypes.WinError()
            break
        dwNeeded = DWORD()
        if (not SetupDiGetDeviceInterfaceDetail(g_hdi, ctypes.byref(did), None, 0, ctypes.byref(dwNeeded), None)):
            if (ctypes.GetLastError() != ERROR_INSUFFICIENT_BUFFER):
                raise ctypes.WinError()
        class SP_DEVICE_INTERFACE_DETAIL_DATA_A(ctypes.Structure, ):
            _fields_ = [('cbSize', DWORD), ('DevicePath', (CHAR * (dwNeeded.value - ctypes.sizeof(DWORD))))]
            def __str__(self):
                return ('DevicePath:%s' % (self.DevicePath,))
        idd = SP_DEVICE_INTERFACE_DETAIL_DATA_A()
        idd.cbSize = SIZEOF_SP_DEVICE_INTERFACE_DETAIL_DATA_A
        devinfo = SP_DEVINFO_DATA()
        devinfo.cbSize = ctypes.sizeof(devinfo)
        if (not SetupDiGetDeviceInterfaceDetail(g_hdi, ctypes.byref(did), ctypes.byref(idd), dwNeeded, None, ctypes.byref(devinfo))):
            raise ctypes.WinError()
        szHardwareID = ctypes.create_string_buffer(250)
        if (not SetupDiGetDeviceRegistryProperty(g_hdi, ctypes.byref(devinfo), SPDRP_HARDWAREID, None, ctypes.byref(szHardwareID), (ctypes.sizeof(szHardwareID) - 1), None)):
            if (ctypes.GetLastError() != ERROR_INSUFFICIENT_BUFFER):
                raise ctypes.WinError()
        szFriendlyName = ctypes.create_string_buffer(1024)
        if (not SetupDiGetDeviceRegistryProperty(g_hdi, ctypes.byref(devinfo), SPDRP_FRIENDLYNAME, None, ctypes.byref(szFriendlyName), (ctypes.sizeof(szFriendlyName) - 1), None)):
            if (ctypes.GetLastError() !=...