更改 Windows 7 中命令提示符的默认启动目录

发布于 2024-10-16 03:31:05 字数 187 浏览 5 评论 0 原文

如何更改 Windows 7 中命令提示符的默认启动目录?

我通常执行以下操作从 C:\ 启动命令提示符

  WIN-R (Run Prompt)
  cmd /K cd C:\

我想执行以下操作从 C:\ 启动命令提示符

  WIN-R (Run Prompt)
  cmd

How do I change default startup directory for command prompt in Windows 7?

I usually do the following to start command prompt from C:\

  WIN-R (Run Prompt)
  cmd /K cd C:\

I want to do the following to start command prompt from C:\

  WIN-R (Run Prompt)
  cmd

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(24

诠释孤独 2024-10-23 03:31:06

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

暮色兮凉城 2024-10-23 03:31:06

一种简单的方法+奖金。

以管理员权限启动cmd,提示符默认目录为C:\WINDOWS\system32

我在该目录中创建了一个bat文件(notes.bat
用记事本打开它并写入以下几行。每行后面都有一个注释,不应将其添加到 bat 文件中。

@echo off

prompt $S$CYourNamel$F$S$G$S 
/* This is a comment, do not include it in the bat file - above line will make the prompt look like  (YourName) > */

cd C:\Your_favorite_directory
/* This is a comment, do not include it in the bat file - above line will navigate you to your desired directory */

保存文件就这样了。
现在,当您以管理员权限打开cmd时,只需编写:notesnotes.bat
它将执行带有所需更改的 notes.bat 文件。

One easy way to do it + bonus.

Start cmd with administrator rights, the default directory for the prompt will be C:\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.

@echo off

prompt $S$CYourNamel$F$S$G$S 
/* This is a comment, do not include it in the bat file - above line will make the prompt look like  (YourName) > */

cd C:\Your_favorite_directory
/* This is a comment, do not include it in the bat file - above line will navigate you to your desired directory */

Saved the file and that was it.
Now when You open cmd with admin rights, just write: notes or notes.bat
and it will execute the notes.bat file with desired changes.

|煩躁 2024-10-23 03:31:06
  1. 转到regedit(转到搜索并键入regedit)
  2. 展开HKEY_CURRENT_USER节点下的“HKEY_CURRENT_USER”节点
  3. 展开软件
  4. 节点下的“software”节点展开microsoft节点下的“microsoft”节点
  5. 单击“命令处理器”
  6. 路径如下所示:“HKEY_CURRENT_USER\Software \Microsoft\Command Processor"

它看起来像这样:

  1. 如果您没有看到“Autorun”字符串值
  2. 右键单击 - 新建 - 可扩展字符串值,并将其重命名为自动运行,
  3. 双击“自动运行”
    10.输入此值路径格式:
  4. “CD/d C:\yourfoldername\yoursubfoldername”
  1. go to regedit ( go to search and type regedit)
  2. expand "HKEY_CURRENT_USER" node
  3. under HKEY_CURRENT_USER node expand "software" node
  4. under software node expand "microsoft" node
  5. under microsoft node click on "Command Processor"
  6. path looks like this : "HKEY_CURRENT_USER\Software\Microsoft\Command Processor"

it looks something like this :

  1. if you do not see "Autorun" String Value
  2. Right Click - New - Expandable String Value, and rename it to Autorun
  3. double click on "Autorun"
    10.enter this value path format:
  4. "CD/d C:\yourfoldername\yoursubfoldername"
鹿港巷口少年归 2024-10-23 03:31:06

编辑:实际上,编辑文件快捷方式似乎会破坏 Win+xc 键快捷方式。 (这个故事的寓意是:只更改您知道如何修复的系统文件!最终,在 Windows 更新后,它会自行修复。)

我最终所做的是在开始文件夹中创建一个新的自定义命令提示符快捷方式,并将其固定到我的任务栏上 正如其他答案指出的那样


,更改注册表 Autorun cmd 启动位置是一个坏主意,因为它会默默地破坏其他执行任务的程序,例如 Visual Studio Code。

您应该只更改用于打开 cmd 的任何快捷方式以具有“开始”条目。

如果您使用 Win+xc 启动 cmd,您可以编辑 Start In

"%LOCALAPPDATA%\Microsoft\Windows\WinX\Group3\02 - Command Prompt.lnk"

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

"%LOCALAPPDATA%\Microsoft\Windows\WinX\Group3\02 - Command Prompt.lnk"
我ぃ本無心為│何有愛 2024-10-23 03:31:06

键入

cmd.exe /k cd c:/

一个文本文件并另存为 cmd.bat 单击此文件即可解决问题。您也可以将其固定到开始菜单。

要在分区驱动器(例如 D)中启动,请使用

cmd.exe /k d:

type

cmd.exe /k cd c:/

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.exe /k d:
无所谓啦 2024-10-23 03:31:06

启动 CMD 时,我的默认目录是 system32。
然后,我在该目录中创建了一个批处理文件,将目录更改为我想要的目录。

这导致我每次启动CMD时总是调用那个bat。
所以我制作了一个 reg 文件 &把它放进去:

Windows Registry Editor Version 5.00

[HKEY_CURRENT_USER\Software\Microsoft\Command Processor]
"Autorun"="cd C:\\Users\\Me\\SomeFolder"

保存后,我打开文件,单击“确定”与注册表合并,从那以后每次我打开 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:

Windows Registry Editor Version 5.00

[HKEY_CURRENT_USER\Software\Microsoft\Command Processor]
"Autorun"="cd C:\\Users\\Me\\SomeFolder"

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

桃酥萝莉 2024-10-23 03:31:06

在新的 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.

风筝有风,海豚有海 2024-10-23 03:31:06

使用 Windows 终端配置起始目录
部分settings.json

{
    // Make changes here to the cmd.exe profile.
    "guid": "{0caa0dad-35be-5f56-a8ff-afceeeaa6101}",
    "name": "Command Prompt",
    "commandline": "cmd.exe",
    "hidden": false,
    "startingDirectory": "C:\\DEV"
},

Use Windows Terminal and configure a starting directory.
Partial settings.json:

{
    // Make changes here to the cmd.exe profile.
    "guid": "{0caa0dad-35be-5f56-a8ff-afceeeaa6101}",
    "name": "Command Prompt",
    "commandline": "cmd.exe",
    "hidden": false,
    "startingDirectory": "C:\\DEV"
},
墨落画卷 2024-10-23 03:31:06

HKEY_CURRENT_USER\Software\Microsoft\Command Processor 不再有效。

新密钥在这里:

HKEY_LOCAL_MACHINE\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:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Command Processor

Change "Autorun" to "CD /d C:\YourFolder" (without double quotes)

永言不败 2024-10-23 03:31:06

保持命令提示符的开头干净。避免编辑注册表项和添加自动运行,它可能会反过来咬你。
创建一个简单的批处理文件并将其保存在 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.

清晨说晚安 2024-10-23 03:31:06

“在目录中启动”命令

cmd /K cd C:\WorkSpace

,但如果 WorkSpace 恰好位于与 C 驱动器不同的位置,控制台将在默认文件夹中启动,然后您仍然需要放入 D: 来更改驱动器
为了避免这种情况,请使用 cd 和 -d 参数

cmd /K cd -d D:\WorkSpace

创建一个快捷方式并进行修复;)

"start in directory" command

cmd /K cd C:\WorkSpace

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

cmd /K cd -d D:\WorkSpace

create a shortcut and your fixed ;)

最单纯的乌龟 2024-10-23 03:31:06

你好,如果你想让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)

夜唯美灬不弃 2024-10-23 03:31:06

regedit 效果很好。 HKEY_CURRENT_USER\SOFTWARE\MICROSOFT\Command 处理器,您所要做的就是更改 AutoRun 键值,该值已设置为您当前转储到的任何位置,格式为

cd /d <drive:path>

for c:\, that would be cd /d c:\
for junk, that would be cd d/ c:\junk

:很简单,即使是从未使用过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:

cd /d <drive:path>

for c:\, that would be cd /d c:\
for junk, that would be cd d/ c:\junk

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.

め可乐爱微笑 2024-10-23 03:31:05

创建一个指向 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.

傲鸠 2024-10-23 03:31:05

以下解决方案对我来说效果很好。导航到开始菜单中的命令提示符快捷方式:

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.

没有你我更好 2024-10-23 03:31:05

打开 regedit 并浏览到此路径

HKEY_CURRENT_USER\Software\Microsoft\Command Processor

创建名为 Autorun 的新字符串 vale。将其值设置为 cd /d C:\。

再次运行cmd。瞧!

Open regedit and browse to this path

HKEY_CURRENT_USER\Software\Microsoft\Command Processor

Create new string vale named Autorun. Set its value to cd /d C:\.

Run cmd again. Voila!

夜夜流光相皎洁 2024-10-23 03:31:05

AutoRun 条目添加到 时HKEY_CURRENT_USER\Software\Microsoft\Command Processor 像 Shinnok 的答案是要走的路 它也会把事情搞砸,你真的应该尝试检测简单的 cmd.exe 启动与脚本/使用 cmd.exe 作为子进程的程序:

IF /I x"%COMSPEC%"==x%CMDCMDLINE% (cd /D c:\)

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:

IF /I x"%COMSPEC%"==x%CMDCMDLINE% (cd /D c:\)
秋凉 2024-10-23 03:31:05

最简单的方法是

  1. 单击“开始”并键入“cmd”或“命令提示符”。
  2. 选择名称完全相同的“cmd”或“命令提示符”的最热门搜索应用程序。
  3. 右键单击它并选择“发送到”=>“桌面”。
  4. 在桌面上将出现新的“cmd”快捷方式
  5. 右键单击​​该图标并选择“属性”
  6. 将出现弹出窗口,在“快捷方式”选项卡中在“开始于”选项中键入新位置(例如 D:\xyz)
  7. 拖动该图标并将其添加/固定在“任务栏”中

Easiest way to do this

  1. Click "Start" and type "cmd" or "command prompt".
  2. Select Top most search application named exactly same "cmd" or "command prompt".
  3. Right Click on it and select "Send To"=>"Desktop".
  4. On Your Desktop New "cmd" Shortcut will appear
  5. Right Click on that icon and choose "properties"
  6. Popup will appear, In "Shortcut" Tab Type the new location in "Start In" option (e.g D:\xyz)
  7. Drag that icon and add/pin it in "Task Bar"
魂牵梦绕锁你心扉 2024-10-23 03:31:05

在 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

久随 2024-10-23 03:31:05

有点晚了,但忽略注册表模组。
只需将快捷方式目标更改为:

cmd /k "command"

cmd /k "cd\myStartUpFolder"

瞧!

Bit late but ignore the registry mods.
Simply change the shortcut target to:

cmd /k "command"

i.e.

cmd /k "cd\myStartUpFolder"

Voila!

廻憶裏菂餘溫 2024-10-23 03:31:05

这对我不起作用。我已经在 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:)"

不及他 2024-10-23 03:31:05

我认为最简单的方法是创建一个 cmd 快捷方式,然后将快捷方式的“Start in”目录更改为您想要开始的目录。

descripted_image

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.

described_image

つ可否回来 2024-10-23 03:31:05

在 Windows 7 上:

  1. 在 Windows 计算机上搜索“cmd”
  2. 右键单击 cmd,然后左键单击“固定到开始菜单”(或者,右键单击 cmd - 单击复制,然后粘贴到桌面)
  3. 右键单击开始菜单或桌面上的 cmd(取决于上面的选项 2)- 左键单击属性
  4. 在“开始于”文本框中粘贴默认开始目录的位置
  5. 按“应用”并单击“确定”

每次您单击开始菜单或桌面快捷方式中的 cmd 时,CMD 都会在您的默认位置

On windows 7:

  1. Do a search for "cmd" on your Windows computer
    1. right-click cmd and left click "Pin to start menu" (Alternatively, right-click cmd - click copy and then paste to your desktop )
    2. right-click the cmd in your start menu or on your desktop (depending on choice 2 above) - left click properties
    3. inside the "start in" text box paste the location of your default start directory
    4. Press Apply and OK

Every time you click on the cmd in your start menu or your desktop shortcut, the CMD will open in your default location

_失温 2024-10-23 03:31:05

在 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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文