Earlier this week, I've been hit by a problem with the console font unexpectedly changing when I ran a new batch script on one of my test systems.
I quickly found the root cause, which was another PowerShell script called from a batch script.
Surprisingly, the PowerShell script was innocent. It's PowerShell itself that always changes the cmd.exe console font to the Terminal raster font, anytime it's invoked on that machine.
I have no idea why this happens on that machine, and not on the other test machines I have.
This apparently has a different cause, but the same disrupting effects, as the problem reported in thread 8205.
Anyway, I started thinking about how to work around that, and I eventually found a way to automate it:
I already had a C program that enumerated the console font sizes.
All I had to do was to add options for saving the current font name and size, then restoring them later on.
Here comes font.exe version 2.0, available at:
https://github.com/JFLarvoire/SysToolsLib/releases
Example run on the machine that has the unstable font issue:
Display the current font:
Code: Select all
F:\Temp>font
[TrueType] Lucida Console (8 x 14)
F:\Temp>
Code: Select all
F:\Temp>font -l
CHARACTERS CHARSET TYPE NAME
'\x01'-'\xFE' OEM Raster Terminal
'\x20'-'\xFF' ANSI Raster Fixedsys
'\x20'-'\xFF' ANSI Raster Courier
'\x00'-'\xFF' ANSI Device HPE Simple
'\x00'-'\xFF' ANSI Device HPE Simple Light
'\x00'-'\xFF' ANSI TrueType Consolas
'\x1E'-'\xFF' ANSI TrueType Courier New
'\x1E'-'\xFF' BALTIC TrueType Courier New Baltic
'\x1E'-'\xFF' EASTEUROPE TrueType Courier New CE
'\x1E'-'\xFF' RUSSIAN TrueType Courier New CYR
'\x1E'-'\xFF' GREEK TrueType Courier New Greek
'\x1E'-'\xFF' TURKISH TrueType Courier New TUR
'\x1E'-'\xFF' ANSI TrueType Lucida Console
'\x00'-'\xFF' ANSI TrueType MS Gothic
'\x00'-'\xFF' ANSI TrueType @MS Gothic
'\x1E'-'\xFF' ANSI TrueType NSimSun
'\x1E'-'\xFF' ANSI TrueType @NSimSun
'\x1E'-'\xFF' ANSI TrueType SimSun-ExtB
'\x1E'-'\xFF' ANSI TrueType @SimSun-ExtB
'\x1E'-'\xFF' ANSI TrueType Lucida Sans Typewriter
Total: 20 fonts
F:\Temp>
Code: Select all
F:\Temp>for /f "delims=" %f in ('font -s') do @set OLD_FONT=%f
F:\Temp>set OLD_FONT
OLD_FONT="Lucida Console" 8x14
F:\Temp>powershell -c $PSVersionTable
Name Value
---- -----
PSVersion 5.1.16299.666
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.16299.666
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
F:\Temp>font
[Raster] Terminal (8 x 12)
F:\Temp>font %OLD_FONT%
F:\Temp>font
[TrueType] Lucida Console (8 x 14)
F:\Temp>
Limitations:
- Does not work in Windows XP, due to the GetCurrentConsoleFontEx() API missing there. font.exe runs, but does not detect the current font name.
Any help at achieving the same results with the old APIs is welcome!
- Conversely, in Windows 10, the GetConsoleFontInfo() API returns no information about other available font sizes.
And for the older versions of Windows up to 8, the information it returns is indirect only, leading to font.exe option -p sometimes listing incorrect sizes (especially for large font sizes).
Any help at finding a reliable way to get available font sizes for all versions of Windows is welcome!
Enjoy!
Jean-François