Most drill the windows, then paint, then fill the windows, and then assemble the model. Then you clean up the seam line, then touch up the paint.
I tried to do the opposite on a recent model, where I masked off the windows. It was a real pain, but it came out good.
The problem with masking the windows is that you have to mask quite a few windows. The model I was building only had 20 windows, not a problem. But a Star Trek ship would have hundreds.....
Another method I have tired is to not drill out the windows, then light block on the outside of the ship and then scrape off the paint on the windows. Again I used a masking fluid on the windows before paint. It worked well, but I would definitely practice this on scrap material. If you don't cut the paint around the outside of the windows before scraping the paint, you will not get a good result.