Page 1 of 1

Setting up scripting environment

Posted: 16 Mar 2015 13:44
by Matt Williamson
Every day, I come in to work and open up 2 cmd prompts. I change the titles and set each one to a specific folder. I've been trying to write the script to do this so I can just double click a file and have it done for me. I haven't figured it out yet. Something like:

Code: Select all

@echo off

cmd.exe /K title test1&"cd /d G:\Scripts1\batch"
cmd.exe /K title test2&"cd /d F:\Scripts\batch"


TIA

Matt

Re: Setting up scripting environment

Posted: 16 Mar 2015 14:54
by Squashman

Code: Select all

@echo off

start "" cmd.exe /K "title test1 & cd /d H:"
start "" cmd.exe /K "title test2 & cd /d W:"

Re: Setting up scripting environment

Posted: 17 Mar 2015 07:07
by Matt Williamson
Nice Squashman. Now comes the tough part. It isn't picking up the settings that I've already set for any CMD window because the title isn't cmd.exe. I can get it close using MODE like so:

Code: Select all

@echo off

start "" cmd.exe /K "title Batch Folder & cd /d F:\Scripts\batch & color 0A & mode con:cols=130 lines=2500"
start "" cmd.exe /K "title Hermes Dev Testing & cd /d G:\ITF\Hermes Install\dev & mode con:cols=130 lines=2500 & color 0A"


But I can't get Font name, Font size or Font bold from a command. So, I've tried editng the registry in a Pre-prep.cmd file like so:

Code: Select all

@echo off
mode con:cols=130 lines=2500
set mySysRoot=%%SystemRoot%%
reg add "HKCU\Console\%mySysRoot%_system32_cmd.exe" /v FaceName /t REG_SZ /d Lucinda Console /f
reg add "HKCU\Console\%mySysRoot%_system32_cmd.exe" /v FontSize /t REG_DWORD /d 00140000 /f
reg add "HKCU\Console\%mySysRoot%_system32_cmd.exe" /v FontWeight /t REG_DWORD /d 000002bc /f
reg add "HKCU\Console\%mySysRoot%_system32_cmd.exe" /v QuickEdit /t REG_DWORD /d 1 /f
"Prepare Environment.cmd"


but all I get is a tiny window that pops up then disappears and now my defaults for new windows has changed. My font size is now 2. I originally saved a .reg file so I can get them back easily but I can't figure out what I need to put in my pre-env-prep script. Here is the .reg file:

Code: Select all

Windows Registry Editor Version 5.00

[HKEY_CURRENT_USER\Console\%SystemRoot%_system32_cmd.exe]
"ScreenColors"=dword:0000000a
"ScreenBufferSize"=dword:03e70078
"WindowSize"=dword:001e0064
"WindowPosition"=dword:0007000e
"FontSize"=dword:00140000
"FontFamily"=dword:00000036
"FontWeight"=dword:000002bc
"FaceName"="Lucida Console"
"HistoryBufferSize"=dword:00000063
"NumberOfHistoryBuffers"=dword:00000032
"HistoryNoDup"=dword:00100000
"QuickEdit"=dword:00000001


Any suggestions?

Thanks!

Matt

Re: Setting up scripting environment

Posted: 20 Jan 2016 06:54
by foxidrive
Did you sort this out Matt?

Re: Setting up scripting environment

Posted: 20 Jan 2016 08:31
by Matt Williamson
No, Foxidrive I never did. Honestly, it was so long ago that I forgot all about it. I'd still like to figure it out though. Any thoughts?

Re: Setting up scripting environment

Posted: 20 Jan 2016 17:53
by thefeduke
Matt Williamson wrote:No, Foxidrive I never did. Honestly, it was so long ago that I forgot all about it. I'd still like to figure it out though. Any thoughts?
It strikes me that this works with just a desktop shortcut. I put a little zipped file on http://1drv.ms/1RTK4wi that would give you this:Image

If the sharing link doesn't work, send me a Edit: Private Message with your e-mail address and I'll send it to you directly.
John A.

Re: Setting up scripting environment

Posted: 21 Jan 2016 02:47
by foxidrive
Matt Williamson wrote:I'd still like to figure it out though. Any thoughts?

I'm not sure which part was the issue, but I was just going to suggest echoing the reg file to a temp file and using regedit to merge it into the registry.

The path for %systemroot% may be better off hard coded - it's up to you.

Code: Select all

@echo off
(
echo(Windows Registry Editor Version 5.00
echo(
echo([HKEY_CURRENT_USER\Console\%SystemRoot%_system32_cmd.exe]
echo("ScreenColors"=dword:0000000a
echo("ScreenBufferSize"=dword:03e70078
echo("WindowSize"=dword:001e0064
echo("WindowPosition"=dword:0007000e
echo("FontSize"=dword:00140000
echo("FontFamily"=dword:00000036
echo("FontWeight"=dword:000002bc
echo("FaceName"="Lucida Console"
echo("HistoryBufferSize"=dword:00000063
echo("NumberOfHistoryBuffers"=dword:00000032
echo("HistoryNoDup"=dword:00100000
echo("QuickEdit"=dword:00000001
)>temp.reg
regedit /s  temp.reg
del temp.reg

Re: Setting up scripting environment

Posted: 23 Sep 2016 04:45
by michealespinola
This should work - it did on my system:

test.cmd:

Code: Select all

START "Window 1" CD /D C:\Directory1
START "Window 2" CD /D C:\Directory2
REM ...
ECHO Profit!

Re: Setting up scripting environment

Posted: 23 Sep 2016 06:19
by Squashman
michealespinola wrote:This should work - it did on my system:

test.cmd:

Code: Select all

START "Window 1" CD /D C:\Directory1
START "Window 2" CD /D C:\Directory2
REM ...
ECHO Profit!

Read the whole thread. There is a little more to it then just open another cmd.exe instance and changing to a directory.

Re: Setting up scripting environment

Posted: 23 Sep 2016 11:39
by douglas.swehla
Squashman wrote:
michealespinola wrote:This should work - it did on my system:

test.cmd:

Code: Select all

START "Window 1" CD /D C:\Directory1
START "Window 2" CD /D C:\Directory2
REM ...
ECHO Profit!

Read the whole thread. There is a little more to it then just open another cmd.exe instance and changing to a directory.


It looks like foxidrive may have a solution to the formatting problem, so I'll leave that alone for now. Micheal seems to be the first in the thread to set the title using the required argument to START, rather than passing cd /d path\to\directory to CMD, which is surprising. Have we gotten so used to typing start "" cmd [args] that the empty quotes don't register anymore, or is there a good reason to do it the long way?

I'm also surprised no one has mentioned that, in addition to the window title, START can also set the starting path. I would replace the first bit of code with the second.

Code: Select all

:: Original: Setting window title and current directory by passing commands as arguments to CMD.
start "" cmd.exe /K "title Batch Folder       & cd /d F:\Scripts\batch          & color 0A & mode con:cols=130 lines=2500"
start "" cmd.exe /K "title Hermes Dev Testing & cd /d G:\ITF\Hermes Install\dev & color 0A & mode con:cols=130 lines=2500"


Code: Select all

:: Modified: Setting window title and current directory by passing them as arguments to START.
start "Batch Folder"       /d "F:\Scripts\batch"          cmd.exe /k "color 0A & mode con:cols=130 lines=2500"
start "Hermes Dev Testing" /d "G:\ITF\Hermes Install\dev" cmd.exe /k "color 0A & mode con:cols=130 lines=2500"


If no other application is specified, START will run CMD /K. So, if all the color, layout, and formatting can be handled elsewhere, these can be further collapsed to

Code: Select all

:: Simplest: No need to specify CMD /K if formatting and layout are done already.
start "Batch Folder"       /d "F:\Scripts\batch"
start "Hermes Dev Testing" /d "G:\ITF\Hermes Install\dev"