command prompt to default to open directory?

N

Nick

This may be a basic question, but does anyone know where to change the
setting for the Command Prompt to default to? For example, some
machines running Windows 2000 always default to the C: drive while
others defautlt to the currently open folder in Explorer. Thanks!!
 
P

Paul R. Sadowski

Nick said:
This may be a basic question, but does anyone know where to change the
setting for the Command Prompt to default to? For example, some
machines running Windows 2000 always default to the C: drive while
others defautlt to the currently open folder in Explorer. Thanks!!

If you are using shortcuts to open the command prompt you can set the "start
in" item (right-click, select properties) to any location you want. I use
%HOMEDRIVE%%HOMEPATH% myself.
 
M

Mark V

In said:
This may be a basic question, but does anyone know where to change
the setting for the Command Prompt to default to? For example,
some machines running Windows 2000 always default to the C: drive
while others defautlt to the currently open folder in Explorer.
Thanks!!

"AutoRun".

Aside from Shortcuts which of course can be set for "Start in:"
And various issue with the HOMEPATH et. al variables,

See:
HKEY_CURRENT_USER\Software\Microsoft\Command Processor\
"AutoRun"=
(REG_SZ)

(and
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Command Processor\ )

Where you specifiy what should "run" for all instances of cmd.exe on
a per-user or per system basis. *1

Example
"AutoRun"="CD /D C:\"

or even "CD /D C:\ & TITLE MyCMD" or any other valid "command line".

This IMHO is the only way to go for "global" settings for CMD and
ignores all issues of HOMEPATH HOMEDRIVE etc. not being what you
might expect or wish them to be.



*1 Suspect it applies to the exectuable defined by COMSPEC. But
never tested that as the default is cmd.exe.
 
N

Nick

Thanks guys. Both worked great to change to a different default
directory, but unfortunately, neither, unless I did something wrong,
seems to open to whatever folder is open in Explorer. I have worked on
one Windows 2000 computer, which would "magically" default to
K:\subfolder if I had My Computer open to K:\subfolder before going to
Start->Run->Command/Cmd; likewise it would default to
c:\subfolder\subfolder if I had Explorer open to that directory. Any
idea where I could look to see how it was done on the computer?

Thanks again!
 
J

Jerold Schulman

Thanks guys. Both worked great to change to a different default
directory, but unfortunately, neither, unless I did something wrong,
seems to open to whatever folder is open in Explorer. I have worked on
one Windows 2000 computer, which would "magically" default to
K:\subfolder if I had My Computer open to K:\subfolder before going to
Start->Run->Command/Cmd; likewise it would default to
c:\subfolder\subfolder if I had Explorer open to that directory. Any
idea where I could look to see how it was done on the computer?

Thanks again!


See tip 594 in the 'Tips & Tricks' at http://www.jsiinc.com

Jerold Schulman
Windows: General MVP
JSI, Inc.
http://www.jsiinc.com
 
M

Mark V

In said:
Thanks guys. Both worked great to change to a different default
directory, but unfortunately, neither, unless I did something
wrong, seems to open to whatever folder is open in Explorer. I
have worked on one Windows 2000 computer, which would "magically"
default to K:\subfolder if I had My Computer open to K:\subfolder
before going to Start->Run->Command/Cmd; likewise it would default
to c:\subfolder\subfolder if I had Explorer open to that
directory. Any idea where I could look to see how it was done on
the computer?

Ah.

See Jerold's answer.

One might also utilize a "Send To" item, but I suspect CMDPromptHere is
what you wanted.
 
N

Nick

Thanks Jerold. That definitely works, but that means you have to back
out of the folder. I know I'm being picky, but I'd really like to
figure out how it is done, and if it can be reproduced on another
machine. Somehow, this machine will open the currently open folder
when you run Command or Cmd from Start->Run. The JSI one is also on
Microsoft's site at http://www.microsoft.com/windows2000/techenthusiast/tricks/administration/registry.asp

Since the command prompts seem to default to the HomePath variable,
maybe there is a way for the Homepath variable to be updated to the
currently open folder?
 
M

Mark V

In said:
Thanks Jerold. That definitely works, but that means you have to
back out of the folder. I know I'm being picky, but I'd really
like to figure out how it is done, and if it can be reproduced on
another machine. Somehow, this machine will open the currently
open folder when you run Command or Cmd from Start->Run. The JSI

Interesting. I've no ideas.
But, why do all that work (Start, Run...) when CMDPromptHere is so
efficient? Or is just academic interest? And any chance it is really
an Explorer add-on that provides a "Run" or "Start" dialog box (that
would start CMD or other in the current directory)...?
 
N

Nick

Hi Mark,

Yeah, at this point, it is just out of interest. The other methods are
probably better, but I'd really like to figure this thing out. There
isn't anything unusual in the Run keys in the registy or in the
Startup folder, nor any unusual running processes or applicatons. I
also checked the homepath variable, and that doesn't seem to be how
its done either. Really weird...
 
G

Gary Smith

Nick said:
Yeah, at this point, it is just out of interest. The other methods are
probably better, but I'd really like to figure this thing out. There
isn't anything unusual in the Run keys in the registy or in the
Startup folder, nor any unusual running processes or applicatons. I
also checked the homepath variable, and that doesn't seem to be how
its done either. Really weird...

I don't think there is an answer to your question. The fact that a folder
is open in Explorer does not make it current for any other process or
application. Consider the situation where you have two or more instances
of Explorer open to different folders. What folder would be "current"
then?
 
A

Al Dunbar [MS-MVP]

Gary Smith said:
I don't think there is an answer to your question. The fact that a folder
is open in Explorer does not make it current for any other process or
application. Consider the situation where you have two or more instances
of Explorer open to different folders. What folder would be "current"
then?

Same thing if you have two command console windows open. The whole concept
of "current directory" is particularly related to the old DOS concept of,
"hey, there is really only one context on this system at any given time".
Once you are working in a specific context of some application, this is
still workable. But the context of one application does not automatically
become the context of the machine.

/Al
 
M

Matthias Tacke

Nick said:
Hi Mark,

Yeah, at this point, it is just out of interest. The other methods are
probably better, but I'd really like to figure this thing out. There
isn't anything unusual in the Run keys in the registy or in the
Startup folder, nor any unusual running processes or applicatons. I
also checked the homepath variable, and that doesn't seem to be how
its done either. Really weird...

If you like to choose which of the open explorer windows should be the
current make a shortcut with this (without line breaks) :

cmd /K for /F "tokens=8,*" %a in ('cmdow /T /F^|findstr "explorer [A-Z]:"') do pushd %b

Requires cmdow.exe from http://www.commandline.co.uk in a path folder.

It pushes all the folders (with drive letters) to the directory stack.
You may then issue popd commands until the desired folder is current.

HTH
 
M

Matthias Tacke

Matthias Tacke said:
If you like to choose which of the open explorer windows should be the
current make a shortcut with this (without line breaks) :

cmd /K for /F "tokens=8,*" %a in ('cmdow /T /F^|findstr "explorer [A-Z]:"') do pushd %b

Requires cmdow.exe from http://www.commandline.co.uk in a path folder.

It pushes all the folders (with drive letters) to the directory stack.
You may then issue popd commands until the desired folder is current.
And here a batch variant with an on screen menu to select the folder.

::SElFld.cmd:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
@echo off & setlocal
for /F "tokens=8,*" %%A in (
'cmdow /T /F^|findstr "explorer [A-Z]:"^|sort /+41') do (
call :Menu "%%B"
)
if not defined MyCnt goto :eof
cls
echo/Select number preceeding desired folder
echo/
for /L %%A in (1,1,%MyCnt%) do (
Call echo/ %%A - %%MyFld%%A%%
if "%count%" LEQ "9" echo/
)
set /P FldNum="Select current folder 1-%MyCnt% :"
if not defined MyFld%FldNum% ECHO MyFld%FldNum% NOT DEFINED & goto :eof
call set MyFld=%%MyFld%FldNum%%%
endlocal & pushd %MyFld%
goto :eof
:Menu Folder
set /A MyCnt+=1
call set MyFld%MyCnt%=%~1
::SElFld.cmd:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

HTH
 
N

Nick

At this point I'm starting to believe that it may just be the version.
Does anyone else have Windows 2000 with a Version of 5.0.2195.4038
that can verify this?
 
G

Gary Smith

Nick said:
At this point I'm starting to believe that it may just be the version.
Does anyone else have Windows 2000 with a Version of 5.0.2195.4038
that can verify this?

My cmd.exe (service pack 3) is version 5.0.2195.4803. Is that what you
meant?
 
M

Mark V

In said:
At this point I'm starting to believe that it may just be the
version. Does anyone else have Windows 2000 with a Version of
5.0.2195.4038 that can verify this?

If you mean the cmd.exe version, 5.0.2195.6824 here (W2K, SP4 + KBA
835732)

I really don't see how Start, Run can be aware of the CD inside
explorer.exe (the file manager GUI). At least not without some type of
hook or 3rd-party tool. OTOH the registry is updated when changing
folders in the GUI (Streams, StreamsMRU) so it could be possible to do
so.
 
N

Nick

Gary Smith said:
My cmd.exe (service pack 3) is version 5.0.2195.4803. Is that what you
meant?

Hi Gary,
Yes, thats it. To rule out the possibility, if you open My Computer to
a folder other than just the C drive and go to Start->Run and type in
CMD and click OK, does the path default to the C:\ drive (or whatever
it normally does) or does it default to the path open in My Computer?
 
G

Gary Smith

Nick said:
Yes, thats it. To rule out the possibility, if you open My Computer to
a folder other than just the C drive and go to Start->Run and type in
CMD and click OK, does the path default to the C:\ drive (or whatever
it normally does) or does it default to the path open in My Computer?

With My Computer open to E:\Data\NT-Info, Start > Run > Cmd opens to D:\,
which is %HomeDrive%%HomePath% on this system. On my machine at work, I
discovered that HomeDrive was set to O: (a mapped network share), and
there Start > Run > Cmd opens to O:\ despite the fact that I almost never
use any folder on that drive.
 
M

Matthias Tacke

Gary said:
With My Computer open to E:\Data\NT-Info, Start > Run > Cmd opens to D:\,
which is %HomeDrive%%HomePath% on this system. On my machine at work, I
discovered that HomeDrive was set to O: (a mapped network share), and
there Start > Run > Cmd opens to O:\ despite the fact that I almost never
use any folder on that drive.
Same here.
At the cost of an additonal dependency I changed my already posted
commandline to make the folder of the mru explorer window the current.

Create/change shortcuts for cmd.exe with this line:
CMD.EXE /K for /F "tokens=8,*" %A in ('cmdow /T /F^|findstr "explorer [A-Z]:"^|linex -h 1') do @pushd %B

You need:
explorer configured to show full path in the title
cmdow.exe from http://www.commandline.co.uk
Linex from http://home.comcast.net/~stewartb/bst.html

using popd you may revert to the "execute in" folder from the shortcut
or the homepath/-drive setting.

HTH
 
G

Gary Smith

Matthias Tacke said:
At the cost of an additonal dependency I changed my already posted
commandline to make the folder of the mru explorer window the current.
Create/change shortcuts for cmd.exe with this line:
CMD.EXE /K for /F "tokens=8,*" %A in ('cmdow /T /F^|findstr "explorer [A-Z]:"^|linex -h 1') do @pushd %B

What happens if more than one explorer windows is open?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top