I have 2two methods that I use:
Something that attracts them, usually the source itself placed outside ththe window. They will eventually gravitate towards it and once most of them are outside I quickly remove the rotten fruit and close the window.
But there are usually some that stay behind. For them I use a flame thrower to burn them in mid-flight. I use a blowtorch that is attached to a gas cartridge. If you turn the whole apparatus upside down the liquid gas will pour through the nozzle throwing a big ball of flames. Just be careful using it close to walls. The oxygen starved flame produces soot that can deposit on the wall.