You are not logged in.
Hi
How to check console window width columns in bath script from registry?
HKCU\Console
WindowSize = 1638480
Columns=80
Rows=25
How to calculate?
Offline
Are you asking how the "WindowSize" figure was calculated from the Columns/Rows?
Playing around with the numbers, I managed to reverse engineer them into this:
((80*25*1024*8)/10)+80 = 1638480
But that was dumb luck, and doesn't hold up for other values (it also makes no sense) so you should ignore it
Looks like this is the operation they are doing:
set rows=25
set columns=80
set /a windowsize="(rows<<16)+columns"
Last edited by bluesxman (02 Apr 2019 17:45)
cmd | *sh | ruby | chef
Offline
How to read from registry console columns value?
WindowSize = 1638480
Offline
reg query hkcu\console /v WindowSize
And to get the value as variable (NB this needs to be run in a script):
@echo off
for /f "usebackq tokens=3" %%a in (`reg query hkcu\console /v WindowSize`) do set /a windowsize=%%a
Turning this into your figures...
set /a "rows=(windowsize >> 16)"
set /a "cols=windowsize - (rows << 16)"
Last edited by bluesxman (02 Apr 2019 17:51)
cmd | *sh | ruby | chef
Offline
Why rows=(windowsize >> 16 ?
Offline
Because that's the way to reverse the bitwise shift they've done under the hood to encode the "80" and "25" in a single value.
Here's what I get when I run the code by hand:
D:\Users\bxm>for /f "usebackq tokens=3" %a in (`reg query hkcu\console /v WindowSize`) do set /a windowsize=%a
D:\Users\bxm>set /a windowsize=0x190050
1638480
D:\Users\bxm>set /a "rows=(windowsize >> 16)"
25
D:\Users\bxm>set /a "cols=windowsize - (rows << 16)"
80
Breaking out the intermediate step because maybe that'll make it clearer:
D:\Users\bxm>set /a "rows_shift=rows << 16"
1638400
D:\Users\bxm>set /a "cols=windowsize - rows_shift"
80
I recommend you read up on Bitwise shifts if you want to understand the underlying process.
Last edited by bluesxman (03 Apr 2019 14:05)
cmd | *sh | ruby | chef
Offline
OK but why 16 ?
Offline
Because they're wanting to store two numbers within a single 32 bit DWORD. So they store one number in the first 16 bits, and the other in the remaining 16 bits.
25 (dec) = 0000 0000 0001 1001 (bin)
shifting it "left" by 16 bits gives:
0000 0000 0001 1001 0000 0000 0000 0000 (bin) = 1638400 (dec)
adding the columns value to this gives 1638480
1638480 (dec) = 0000 0000 0001 1001 0000 0000 0101 0000 (bin)
rows columns
0000 0000 0001 1001 0000 0000 0101 0000
So... you need to bit shift by 16 to get the right part of the DWORD.
Last edited by bluesxman (04 Apr 2019 14:04)
cmd | *sh | ruby | chef
Offline