Arjun
Arjun

Reputation: 1069

change the layout of cmd prompt

I want to change the command prompt layout through batch file. It need to be displayed at center or at some position of the screen, but not at the very top. I tried:

@echo off
COLOR 8f
mode con:cols=80 lines=40 
mode con:top=10

The mode con:cols=80 lines=40 command is working, but mode con:top=10 is not.
Please suggest me right of achieving it.

Upvotes: 1

Views: 9082

Answers (1)

PA.
PA.

Reputation: 29349

To control the properties of a window, you have to

  1. create a profile in the registry under some title. Windows uses the registry to store the settings for command-prompt windows based on the window title.

  2. open a window with a title that matches the one used in the profile

Use the following code as a sample to get you started.

@echo off
setlocal
set mycmdTitle=My Special Command Prompt
Set mycmdHeight=40
Set mycmdWidth=80
Set mycmdBufferHeight=500
Set mycmdBufferWidth=%mycmdWidth%
Set mycmdxPos=0
Set mycmdyPos=120
Set mycmdColor=8f
Set /A mycmdBufferSize=mycmdBufferHeight*0x10000+mycmdBufferWidth
Set /A mycmdWindowPos=mycmdyPos*0x10000+mycmdxPos
Set /A mycmdWindowSize=mycmdHeight*0x10000+mycmdWidth
Set mycmdCmd=Title My First Command Prompt^&Echo.^&Echo.^&Echo.^&Echo.
Call :StartCommandPrompt %mycmdBufferSize% %mycmdColor% %mycmdWindowPos% %mycmdWindowSize% "%mycmdTitle%" "%mycmdCMD%"
endlocal
Goto :EOF

:StartCommandPrompt
REM receives %1=BufferSize %2=Color %3=WindowPos %4=WindowSize %5=Title %6=cmd
reg add "HKCU\Console\%~5" /V ScreenBufferSize /T REG_DWORD /D %1 /F >nul
reg add "HKCU\Console\%~5" /V ScreenColors /T REG_DWORD /D 0x%2 /F >nul
reg add "HKCU\Console\%~5" /V WindowPosition /T REG_DWORD /D %3 /F >nul
reg add "HKCU\Console\%~5" /V WindowSize /T REG_DWORD /D %4 /F >nul
start "%~5" %COMSPEC% /K %6
goto :eof

This code is based on some original code I once found on google, but I can't retrieve it so I cannot give the proper attribution to its original developer.

Upvotes: 3

Related Questions