更改 Windows 7 中命令提示符的默认启动目录
如何更改 Windows 7 中命令提示符的默认启动目录?
我通常执行以下操作从 C:\ 启动命令提示符
WIN-R (Run Prompt) cmd /K cd C:\
我想执行以下操作从 C:\ 启动命令提示符
WIN-R (Run Prompt) cmd
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(24)
HKEY_CURRENT_USER\Software\Microsoft\Command Processor
字符串:自动运行
值: cd /d %~dp0
所有bat文件将从bat文件位置运行
HKEY_CURRENT_USER\Software\Microsoft\Command Processor
string: Autorun
value: cd /d %~dp0
all bat files will run from the bat file location
一种简单的方法+奖金。
以管理员权限启动
cmd
,提示符默认目录为C:\WINDOWS\system32
。我在该目录中创建了一个bat文件(
notes.bat
)用记事本打开它并写入以下几行。每行后面都有一个注释,不应将其添加到 bat 文件中。
保存文件就这样了。
现在,当您以管理员权限打开
cmd
时,只需编写:notes
或notes.bat
它将执行带有所需更改的
notes.bat
文件。One easy way to do it + bonus.
Start
cmd
with administrator rights, the default directory for the prompt will beC:\WINDOWS\system32
.I created a bat file in that directory (
notes.bat
)Opened it with notepad and wrote the following lines. Each line is followed with a comment which should not be added to the bat file.
Saved the file and that was it.
Now when You open
cmd
with admin rights, just write:notes
ornotes.bat
and it will execute the
notes.bat
file with desired changes.它看起来像这样:
10.输入此值路径格式:
it looks something like this :
10.enter this value path format:
编辑:实际上,编辑文件快捷方式似乎会破坏 Win+x、c 键快捷方式。 (这个故事的寓意是:只更改您知道如何修复的系统文件!最终,在 Windows 更新后,它会自行修复。)
我最终所做的是在开始文件夹中创建一个新的自定义命令提示符快捷方式,并将其固定到我的任务栏上 正如其他答案指出的那样
,更改注册表 Autorun cmd 启动位置是一个坏主意,因为它会默默地破坏其他执行任务的程序,例如 Visual Studio Code。
您应该只更改用于打开 cmd 的任何快捷方式以具有“开始”条目。
如果您使用 Win+x、c 启动 cmd,您可以编辑 Start In
Edit: It actually seems that editing the file shortcut breaks the Win+x, c key shortcut. (Moral of the story: only change system files you know how to fix! Eventually after a Windows update it repaired itself.)
What I ended up doing is creating a new customized Command Prompt shortcut in the start folder and pinned to the taskbar that I launch instead of
cmd.exe
As other answers point out, changing the registry Autorun cmd start location is a bad idea because it silently will break other programs that shell out for tasks, like Visual Studio Code.
You should just change whatever shortcut you use to open cmd to have a Start In entry.
If you use Win+x, c to launch cmd, you can edit the Start In for
键入
一个文本文件并另存为 cmd.bat 单击此文件即可解决问题。您也可以将其固定到开始菜单。
要在分区驱动器(例如 D)中启动,请使用
type
in a text file and save as cmd.bat Clicking this file does the trick. You can pin it to the start menu as well.
To start in a partitioned drive (e.g. D), use
启动 CMD 时,我的默认目录是 system32。
然后,我在该目录中创建了一个批处理文件,将目录更改为我想要的目录。
这导致我每次启动CMD时总是调用那个bat。
所以我制作了一个 reg 文件 &把它放进去:
保存后,我打开文件,单击“确定”与注册表合并,从那以后每次我打开 CMD 时,我都会得到我的目录
My default dir was system32 when starting CMD.
I then created a batch file in that directory to change dir to the one I was after.
This caused me to always call that bat when starting CMD every time.
So I made a reg file & put this inside:
After saving it, I opened the file, clicked ok to merge with registry, and since then every time I open CMD, I get my dir
在新的 Windows 终端中,您可以单击“设置”并编辑“startingDirectory”行来实现类似的功能。
但请注意,这仅更改 Windows 终端中的默认启动目录,而不更改全局命令提示符的默认启动目录。
In the new Windows Terminal, you can click Settings and edit the line "startingDirectory" to achieve something similar.
Please note, however, that this changes the default startup directory only in Windows Terminal, and not for the command prompt globally.
使用 Windows 终端 和 配置起始目录。
部分
settings.json
:Use Windows Terminal and configure a starting directory.
Partial
settings.json
:HKEY_CURRENT_USER\Software\Microsoft\Command Processor
不再有效。新密钥在这里:
将“Autorun”更改为“CD /d C:\YourFolder”(不带双引号)
HKEY_CURRENT_USER\Software\Microsoft\Command Processor
is no longer valid.The new key is here:
Change "Autorun" to "CD /d C:\YourFolder" (without double quotes)
保持命令提示符的开头干净。避免编辑注册表项和添加自动运行,它可能会反过来咬你。
创建一个简单的批处理文件并将其保存在 C:\Windows 或 C:\Windows\System32 文件夹中。我称我的为 !.bat(感叹号)。它具有以下命令:
@echo off
丙:
光盘 \
CLS
whoami
它会转到我需要工作的文件夹,清除屏幕并告诉我所处的安全上下文。
Keep the opening of the command prompt clean. Avoid editing the registry key and adding an Autorun, it may come back to bite you.
Create a simple batch file and save it in the C:\Windows or C:\Windows\System32 folder. I call mine !.bat (exclamation mark). It has the following commands:
@echo off
c:
cd \
cls
whoami
It goes to the folder where I need to work, clears the screen and tells me what security context I'm in.
“在目录中启动”命令
,但如果 WorkSpace 恰好位于与 C 驱动器不同的位置,控制台将在默认文件夹中启动,然后您仍然需要放入 D: 来更改驱动器
为了避免这种情况,请使用 cd 和 -d 参数
创建一个快捷方式并进行修复;)
"start in directory" command
but if WorkSpace happens to be on different than C drive, console will be launched in default folder and then you still need to put D: to change drive
To avoid this use cd with -d parameter
create a shortcut and your fixed ;)
你好,如果你想让cmd在机器启动时自动打开,你可以将cmd.exe可执行文件放在启动文件夹中(只需搜索启动并在那里放置cmd.exe的快捷方式)
hi if you want cmd to automatically open when the machine starts up you can place the cmd.exe executable in the startup folder(just search for startup and place a shortcut of cmd.exe there)
regedit 效果很好。
HKEY_CURRENT_USER\SOFTWARE\MICROSOFT\Command
处理器,您所要做的就是更改 AutoRun 键值,该值已设置为您当前转储到的任何位置,格式为:很简单,即使是从未使用过regedit的新手也应该能够弄清楚。如果没有,请转到 c:\prompt 并输入 regedit,然后按照密钥的路径进行操作。
regedit worked great.
HKEY_CURRENT_USER\SOFTWARE\MICROSOFT\Command
Processor, all you have to do is change the AutoRun key value, which is already set to wherever you are currently getting dumped into to a new value in the format of:its very simple, even a novice thats never used regedit should be able to figure it out. if not, go to the c:\prompt and just type in regedit, then follow the path to the key.
创建一个指向 cmd.exe 某个位置(例如桌面)的快捷方式,然后右键单击副本并选择“属性”。导航到“快捷方式”菜单并更改“开始于:”目录。
Make a shortcut pointing to cmd.exe somwhere (e.g. desktop) then right-click on the copy and select "properties". Navigate to the "Shortcut" menu and change the "Start in:" directory.
以下解决方案对我来说效果很好。导航到开始菜单中的命令提示符快捷方式:
C:\Users\ 您的用户名 \AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Accessories\Command Prompt
右键单击快捷方式文件以打开属性对话框。在“开始于:”文本框中,您应该看到 %HOMEDRIVE%%HOMEPATH%。如果您希望提示符从 C:\ 开始,只需将变量替换为“C:\”(不带引号)。
更新
Microsoft 最近似乎更改了此行为,因此现在需要执行额外的步骤。执行上述步骤后,复制修改后的快捷方式“命令提示符”并将其重命名为“cmd”。然后,当在开始菜单中键入“cmd”时,它应该再次工作。
The following solution worked well for me. Navigate to the command prompt shortcut in the start menu:
C:\Users\ your username \AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Accessories\Command Prompt
Right click on the shortcut file to open the properties dialog. Inside the "Start in:" textbox you should see %HOMEDRIVE%%HOMEPATH%. If you want the prompt to start in C:\ just replace the variables with "C:\" (without quotes).
update
It appears that Microsoft has changed this behavior recently and so now an additional step is required. After performing the steps above copy the modified shortcut "Command Prompt" and rename it to "cmd". Then when typing "cmd" in the start menu it should once again work.
打开 regedit 并浏览到此路径
创建名为
Autorun
的新字符串 vale。将其值设置为 cd /d C:\。再次运行cmd。瞧!
Open regedit and browse to this path
Create new string vale named
Autorun
. Set its value tocd /d C:\
.Run cmd again. Voila!
将 AutoRun 条目添加到
时HKEY_CURRENT_USER\Software\Microsoft\Command Processor
像 Shinnok 的答案是要走的路 它也会把事情搞砸,你真的应该尝试检测简单的 cmd.exe 启动与脚本/使用 cmd.exe 作为子进程的程序:While adding a AutoRun entry to
HKEY_CURRENT_USER\Software\Microsoft\Command Processor
like Shinnok's answer is the way to go it can also really mess things up, you really should try to detect a simple cmd.exe startup vs a script/program using cmd.exe as a child process:最简单的方法是
Easiest way to do this
在 Windows 开始菜单上,右键单击命令提示符。
单击“属性”。
“命令提示符属性”对话框打开。
将“开始于”字段编辑到要启动命令提示符的位置。
示例:将 %HOMEDRIVE%%HOMEPATH% 更改为 D:\PersonalPrograms。
下次启动命令提示符时,启动目录将为 D:\PersonalPrograms
On Windows Start Menu, right click on Command Prompt.
Click on "Properties".
"Command Prompt Properties" dialog box opens.
Edit the field "Start in " to a location where you want to start the command prompt.
Example: Chand %HOMEDRIVE%%HOMEPATH% to D:\PersonalPrograms.
Next time when you start command prompt the start up directory will be D:\PersonalPrograms
有点晚了,但忽略注册表模组。
只需将快捷方式目标更改为:
即
瞧!
Bit late but ignore the registry mods.
Simply change the shortcut target to:
i.e.
Voila!
这对我不起作用。我已经在 Win7 64 位和 Vista 32 下尝试过此操作
。我使用下面的命令行来添加此功能。
reg add "HKEY_CURRENT_USER\Software\Microsoft\Command Processor" /v AutoRun /t REG_SZ /d "IF x"%COMSPEC%"==x%CMDCMDLINE% (cd /D c:)"
This doesn't work for me. I've tried this both under Win7 64bit and Vista 32.
I'm using the below commandline to add this capability.
reg add "HKEY_CURRENT_USER\Software\Microsoft\Command Processor" /v AutoRun /t REG_SZ /d "IF x"%COMSPEC%"==x%CMDCMDLINE% (cd /D c:)"
我认为最简单的方法是创建一个
cmd
快捷方式,然后将快捷方式的“Start in”目录更改为您想要开始的目录。I think the easiest way is to make a
cmd
shortcut, then change the shortcut's "Start in" directory to the one you want to start with.在 Windows 7 上:
每次您单击开始菜单或桌面快捷方式中的 cmd 时,CMD 都会在您的默认位置
On windows 7:
Every time you click on the cmd in your start menu or your desktop shortcut, the CMD will open in your default location
在 8.1 上的 Windows 系统下更改快捷方式对我有用 - 我发现的另一件事是“开始于:”在高级 -> 时有效。以管理员身份运行未选中,但是,如果选中,则不起作用
changing shortcut under Windows System on 8.1 worked for me - another thing I found is that 'Start In:' WORKS when Advanced -> Run as admin is UNCHECKED, however, if CHECKED, it does not work