How exactly do designers choose the colors they use?

I've been questioning myself for a while now how UI designers choose the exact colors that they end up using. I think that the Windows 7 user interface is a good example of this (in Windows 10+ everything is just white). Windows 7 file dialog

If you look at the file dialog, we see different shades of blue for the window frame, tool bar, navigation buttons and also for the hovered button. But also the icons use colors that integrate very harmoniously with the rest of the interface.

Is there any concept or pattern behind it (like working with specific HSL ranges) or how did the designers choose the colors there? Somehow I can't imagine that it's all just practice and intuition, and yet in the end someone said "Yes, the colors that make up the button's gradient are fine. We'll use those and no others".

I hope you guys can enlighten me a bit there.