3

EDIT: How do I specify the font of command prompt and the size of the window? I'm using Windows 7 Professional. OK. I'm sorry, I'm trying to use a command to do the above things, so I'm not accepting those "press-the-properties" answer.

54D
  • 209
  • 1
  • 6
  • 17

2 Answers2

5

If you want to change the console font size programmatically, see this page and this page. You basically have to copypaste that module source from the technet page into a new file called SetConsoleFont.psm1 on your local machine. Put it into a folder of the same name without ext (so it becomes SetConsoleFont\SetConsoleFont.psm1). From the command line, powershell -command "echo $env:PSModulePath" to see where you should put that SetConsoleFont\ folder (probably in %userprofile%\Documents\WindowsPowerShell\Modules).

If you want to include that technet script within your batch script and have your batch script create [module_path_dir]\SetConsoleFont\SetConsoleFont.psm1 on the user's machine, I suggest a batch script heredoc would be an easy way to include it and write it dynamically.

With the module in your module path, you can now use it from the cmd line.

powershell -command "&{set-executionpolicy remotesigned; Import-Module SetConsoleFont; Get-ConsoleFontInfo | Format-Table -AutoSize}"

will show you a table of the font sizes available to your console. Choose one from the nFont column and activate it like this:

powershell -command "&{set-executionpolicy remotesigned; Import-Module SetConsoleFont; Set-ConsoleFont 6}"

If all you want to do is resize the console window and buffer, that's much simpler. No modules or importing or execution policy overriding is needed. mode con: cols=n1 lines=n2 will change the window dimensions, and there's a PowerShell one-liner for changing the buffer (scrollback history) size.

:: Resize the console window and increase the buffer to 10000 lines
call :consize 80 33 80 10000

:: put the main part of your bat script here.
:: script
:: script
:: script
:: etc.

goto :EOF

:consize <columns> <lines> <buffercolumns> <bufferlines>
:: change console window dimensions and buffer
mode con: cols=%1 lines=%2
powershell -command "&{$H=get-host;$W=$H.ui.rawui;$B=$W.buffersize;$B.width=%3;$B.height=%4;$W.buffersize=$B;}"
goto :EOF
Community
  • 1
  • 1
rojo
  • 24,000
  • 5
  • 55
  • 101
  • Let me try this. I'll reply ASAP. – 54D Nov 25 '14 at 14:12
  • I (and other people) found that it is not working on Windows 10. The `Import` command and the `Get-ConsoleFontInfo` function return nothing. Some also get permission errors when running the `Set-ConsoleFont` function. – Maitre Bart Jul 30 '20 at 16:16
  • The SetConsoleFont module from the 4sysops.com article is now a broken link. It will redirect you to learn.microsoft.com's "Browse code samples" where you can search for SetConsoleFont but that returns nothing. – Shodan Jun 08 '23 at 19:37
  • I have found a backup of this module at https://github.com/MikeFal/PowerShell/blob/master/SetConsoleFont/SetConsoleFont.psm1 – Shodan Jun 08 '23 at 19:50
0

If you create a shortcut to cmd.exe you can rightclick on it and select "properties". Here you can set font, color, window and buffer size, etc.

MichaelS
  • 5,941
  • 6
  • 31
  • 46