I have often been puzzled by the behaviour of the colour scheme, foreground and background on consoles, particularly the way they change without me asking them to. I was curious how it is implemented.

I presume it works like this:
1. there is a *.lnk object somewhere corresponding to a bat or btm file. It is consulted when the bat or btm is run. They get created transparently. Where do these live? Inside it are embedded two ints, which define the palette slot number of the foreground and background colours.

2. There is onely one copy of the palette itself, If you modify it, it will change the rendering of all the colours in the machine. You need to compose a palette to start that has all the colours in it you will ever want to use in any bat file. You are quite limited. It is hidden away somewhere in the config files for TCC.