6

I spend most of my time on command line ( XP / 7 ) and always find myself customizing the command prompt according to my preferences. This applies to both cmd and powershell prompt.

Width: 140
Height: 40
Left: -4
Top: 20
Font: Lucida Console
Font Size: 16
Text Color: RGB(100,150,200)
QuickEdit Mode: Enabled

Whenever I am on a new server, I would need to do this all over again. How can I automate this process by putting these parameters in a batch file or PowerShell script?

Animesh
  • 4,926
  • 14
  • 68
  • 110

2 Answers2

4

You can look into making calls to update the Windows registry. For example,

REG.EXE add HKCU\Console /v QuickEdit /t REG_DWORD /d 1 /f

will set QuickEdit as the default mode for your command prompt. It's easy to slap this line into a batch file, along with other settings.

  • add Keyname will chose the Key name where to add the value, here HKEY_CURRENT_USER\Console
  • /v is followed by the name of the value to add
  • /t followed by its type
  • /d is followed by the data with which to set the name of the value
  • /f to force write in the registry without prompt

Likewise, you can modify WindowSize which contains 0xhhhhwwww where the first four bytes is the value of the height in hexa (e.g. 0x003E for a height of 62 pixels) and www is the window's width. For your case:

REG.EXE add HKCU\Console /v WindowSize /t REG_DWORD /d 0x0028008c /f

Type REG /? and REG add /? for more options.

Damien
  • 1,161
  • 2
  • 19
  • 31
  • Hi Damien, I like your answer a lot too. I saw that you have deleted your answer earlier and I was actually reconstructing your answer from the browser cache so that at least the knowledge is not lost. Glad to see you have reposted it. – Animesh Oct 29 '11 at 20:56
  • Hi Kishor :) I tried my example out and the values get updated correctly in the registry. However, the content that affects the cmd line when typing "cmd" from the start menu is in HKCU\Console\%SystemRoot%_system32_cmd.exe and I have not figured out how to change this. – Damien Oct 29 '11 at 21:02
  • 3
    Damien, Here is some information about it: http://www.adp-gmbh.ch/win/misc/registry.html. See if it works. ---- Additional links: [Link 1](http://help.wugnet.com/vista/Batch-file-help-ftopict146096.html) // [Link 2](http://www.911cd.net/forums//index.php?s=22388817a994e92c0af7057954a2dc64&showtopic=16413&st=0&p=107165entry107165) – Animesh Oct 29 '11 at 21:09
2

You can use the Registry provider in PowerShell along with the *-Item and *-ItemProperty cmdlets to modify the registry values under this registry key: HKEY_CURRENT_USER\Console.

Keith Hill
  • 194,368
  • 42
  • 353
  • 369
  • Thank you sir for pointing out the right things for me. I am now off to making that script. – Animesh Oct 29 '11 at 20:44
  • This idea would clash with other users accessing a shared computer. A better solution should involve creating an icon for launching cmd that is customized properly. – sf_jeff Dec 31 '17 at 19:35
  • Creating a shortcut would be a fine way to go as well - just not as easily scriptable as the above. Also, not that I suggest changing HKEY_CURRENT_USER - so the change would only impact the user who made these registry changes. Also, if you happen to be on Windows 10, you should check out colortool - https://github.com/Microsoft/console/tree/master/tools/ColorTool – Keith Hill Jan 01 '18 at 20:18