For Batch - Where is CMD.EXE options stored?

Dell / LATITUDE D610
June 25, 2010 at 08:29:38
Specs: Microsoft Windows XP Professional, 2.127 GHz / 1015 MB
I'm writing a batch file that offers a "Usage"
screen that exceeds the default window size of
80 (colums) x 25 (rows). These sizes are
adjustable in the shortcut properties of
cmd.exe, but for the life of me, I don't know
where those are stored so they can be
(temporarily) manipulated! Google didn't help in
this situation, other than offering the GUI
approach of right-click> properties> options>


Insomniac at large

See More: For Batch - Where is CMD.EXE options stored?

Report •

June 25, 2010 at 14:59:13
From just native batch alone the best you can do is size the buffer(i.e where the character cells are) with:

mode con: cols=90 lines=500

or more succinctly:

mode 90,500

For 90 cells wide and 500 cells tall(exchange with you own values of course) .

You will have absolutely no control of how much of the buffer is visible inside the screen window. Mode may change the window to whatever it thinks is suitable.


If you want to size the actual window batch alone isn't capable of doing it(at least to your specified size). If your interested in a utility that can size the actual window you may want to have a look at a tool I wrote recently(free):


Report •

June 25, 2010 at 19:44:29
I just realized that I didn't really answer the question:

The settings are stored in the registry under:



Custom(relating to title)

There is the possibility that the current settings are part of a shortcut......

it's possible to also create a key with <screentitle>(your choice) populate the desired entries that differ from the default and shell out a new console/cmd with 'start "<screentitle>"'.

The reg entries for buffer and window size are DWORD's so you would need to bit shift with set /a and convert the result to hex and then use "reg" to add the values.

Edit: Here is an example of getting the dword - it would still need to be converted to hex:

rem 100 cols
rem 200 lines
set /a "(200 << 16) + 100 "


Stupid me of course you could just set up the values you want as string because it won't need to change.

In my testing on xp setting a window value higher than the system max caused the max to be used instead which is a win.

There is still always the issue of the registry being restricted......

Report •

June 25, 2010 at 21:33:19
Restricted to whom? We're in the HKCU hive.

Report •

Related Solutions

June 25, 2010 at 21:42:46
I was think more along the lines of some sort of draconian group policy type of thing(I don't deal with permissions too often ;) to disable reg.exe.......

What I should have said is "that it will rely on write access to HKEY_CURRENT_USER\Console".

Report •

June 26, 2010 at 05:09:25
Excellent Judago!
I'm now going to have to wrap my mind around adding the
front-end logic for starting the batch (that may already
have arguments) with the START command, like you
mentioned, and prevent the batch from repeatedly starting
itself. I shouldn't have stayed out so late last night!

I'm thinking testing %1's value and SHIFTing (if needed)
should do it...

Thank you for tracking this down!

Insomniac at large

Report •

June 26, 2010 at 14:30:36
Edit: I didn't like my tone...

Ohh no, my head, I'm never going to do that again until next time........

You basically have the right idea and you defiantly
don't won't an infinite loop because there isn't even a fixed
process you can kill..... First time I have used ctrl+alt+del
in a long time....

I was wrong about converting to hex, reg takes decimal
(my bad - testing with regedit).

@echo off
set title=Win=120x30 Buf=120x200
rem windowsize
set /a "win=(30 << 16) + 120"
rem buffer
set /a "buf=(200 << 16) + 120"

if not "%~1"=="__regdone__" (
    >nul reg add "hkcu\console\%title%" /v WindowSize /t REG_DWORD /d "%win%" /f
    >nul reg add "hkcu\console\%title%" /v ScreenBufferSize /t REG_DWORD /d "%buf%" /f
    start "%title%" cmd /c "%~f0" __regdone__ %*
    goto :eof
) else (
    set win=
    set buf=

That's just forcing the values, you may want to check if they
already exist and perhaps even delete them afterwards....

Report •

June 26, 2010 at 21:37:44
I like the idea of using "start" and setting the window
title. The batch could execute reg /query to test the existence
of "hkcu\console\%~n0.usage", and create the key and
details for that particular portion of the batch. If "usage" was
ever needed:

START "%~n0.usage" /WAIT cmd /c %~f0 usage

I'm thinking that would pop open a new instance of the batch
with the proper window size, while the original batch hangs
out (because of the /WAIT) until the child instance terminates.

CALL :%1 2>NUL

would also have to be present at the beginning of the batch...

Insomniac at large

Report •

June 26, 2010 at 23:48:02
You wouldn't strictly *have* to use goto or call, it could easily just be an if statement with all the help being echoed, depending on how you decide to implement the script.

The only real reason to check the reg key is the off chance that it exists as a user set option, the more obscure the title the less chance of it being an issue.

Report •

June 27, 2010 at 02:35:38
I was a bit more verbose when setting Window size and Buffer size variable names:

:: Entry.point.bat

IF "%1" EQU "new_window" (
    2>NUL GOTO %2

SET window_width=120
SET window_height=30
SET /a "window_size=(%window_height% << 16) + %window_width%"

SET buffer_width=120
SET buffer_height=200
SET /a "buffer_size=(%buffer_height% << 16) + %buffer_width%"

>NUL 2>&1 REG QUERY HKCU\Console\%~n0.Usage 
IF !errorlevel! GTR 0 (
    >NUL REG ADD "HKCU\Console\%~n0.Usage" /v WindowSize /t REG_DWORD /d "%window_size%" /f
    >NUL REG ADD "HKCU\Console\%~n0.Usage" /v ScreenBufferSize /t REG_DWORD /d "%buffer_size%" /f

IF "%1" EQU "Usage" (
    START "%~n0.Usage" /WAIT cmd /c %0 new_window Usage

ECHO This should be a regular sized Window.

ECHO This should be a bigger Window.

The only problem is that I want to now query HKEY_CURRENT_CONFIG\System\CurrentControlSet\Control\VIDEO to get the current display resolution, and start playing with Console's WindowPostion settings to center the new window in the screen! :D

Thanks again Judago!

Insomniac at large

Report •

June 27, 2010 at 03:14:57
No problem!

I guess your talking about the "WindowPosition" value to the console entry.

Again it's a higher/lower X/Y Dword, but unfortunately it's not so easy to work this one out. You will need the font, border, title and possibly scroll bar size in pixels, in addition to the screen resolution, before you can work out how many pixels to offset by.

They are probably in the registry *somewhere* but it may take some digging. I'll have a look to see if I can dig any of them up but there are no promises.

Report •

June 27, 2010 at 04:17:32
If the user isn't using the windows default size then getting the font size is easy. However if they are then you would have to guess based on their screen resolution(I haven't the data to even begin to guess other than my 1440x900 default is 10x20)......

I think the default is calculated on invocation, this mirrors my previous bad experiences with the console fonts.

C:\Documents and Settings\judago>reg query hkcu\console
    FaceName    REG_SZ
    FontFamily  REG_DWORD       0x0
    FontSize    REG_DWORD       0x0
    FontWeight  REG_DWORD       0x0

No font size == no way to calculate an offset. I looked through the registry and couldn't find the data anywhere else...


The "raster fonts" seem to date from the 80's.

Report •

June 27, 2010 at 04:30:46
...You will need the font, border, title and possibly scroll
bar size in pixels, in addition to the screen resolution, before
you can work out how many pixels to offset by...

Well, I may just get it "close" to center ;-)

I'm thinking:
Xpos = (DefaultSettings.XResolution - %window_width%) / 2
Ypos = (DefaultSettings.YResolution - %window_height%) /2

would get me close enough.
I'm still working on an x2d function to convert and/or display these REG values

Edit: Well the hex conversion was easy!


FOR /F "tokens=1,3" %%a IN ('REG QUERY HKCC\System\CurrentControlSet\Control\VIDEO /s^|FIND /I "Resolution"') DO (
    IF "%%a" EQU "DefaultSettings.XResolution" SET /A width=%%b+0
    IF "%%a" EQU "DefaultSettings.YResolution" SET /A height=%%b+0

ECHO width=%width%
ECHO height=%height%

Insomniac at large

Report •

June 27, 2010 at 04:39:43
I only just had a look at you script properly and I noticed this:

IF "%1" EQU "Usage"

I would suggest this in it's place:

if /i "%~1"=="usage"

Then you will get a case insensitive compare.

When comparing arguments I suggest to always use %~, you never know when they might already contain double quotes.

Report •

June 27, 2010 at 04:48:51
How did I miss that by 9 minutes.....

I'm thinking:
Xpos = (DefaultSettings.XResolution - %window_width%) / 2
Ypos = (DefaultSettings.YResolution - %window_height%) /2

That's a huge discrepancy, your talking about taking away 30 pixels(assuming 30 character cells) and away from the height that could easily be 600 pixels high not including the title bar or boarders.

Report •

June 27, 2010 at 04:57:52
That's a huge discrepancy, your talking about taking away 30
pixels(assuming 30 character cells) and away from the hight that
could easily be 600 pixels high not including the title bar or

Oh - gotcha...
I'm mixing my unit of measure (pixels vs. character/font size)...
Yep, Xpos & Ypos would be way off...

Insomniac at large

Report •

June 27, 2010 at 05:14:08
Sorry if I'm getting worked up :/ it's a bit like deja vu, except at least it wasn't too hard to get these values with c++ and the api(not that I bothered centring the window).

SET /A width=%%b+0

All you really need to do is:

SET /A width=%%b

Here's the hard part, try converting the other way ;).

Report •

June 27, 2010 at 05:19:51
Convert d2x?
My shared functions :-)

I think I stole d2x from somewhere though...

Edit: As far as you getting worked up, don't fret over it! You got me going in the right direction, and I veered off on a tangent. It's great that you share your experience and knowledge, which DEFINITELY helps prevent me from making mistakes. But with trial and error, I'd like to think that I'd figure out what you were talking about when my window was nowhere near center, and would be thinking to myself: "What is that doing way over there?!" I'm more than satisfied with the answer to my original question! Thanks! :-D

Insomniac at large

Report •

June 27, 2010 at 05:29:19
That's the best batch hex converter I've seen yet(thief! ;). Still limited to a "signed long int" on 32 bit though(a DWORD is an unsigned long int on 32bit).

Report •

Ask Question