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
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.
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.
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!
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:\)
Easiest way to do this
Click "Start" and type "cmd" or "command prompt".
Select Top most search application named exactly same "cmd" or "command prompt".
Right Click on it and select "Send To"=>"Desktop".
On Your Desktop New "cmd" Shortcut will appear
Right Click on that icon and choose "properties"
Popup will appear, In "Shortcut" Tab Type the new location in "Start In" option (e.g D:\xyz)
Drag that icon and add/pin it in "Task Bar"
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:
cmd /k "command"
i.e.
cmd /k "cd\myStartUpFolder"
Voila!
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:)"
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.
On windows 7:
Do a search for "cmd" on your Windows computer
right-click cmd and left click "Pin to start menu" (Alternatively, right-click cmd - click copy and then paste to your desktop )
right-click the cmd in your start menu or on your desktop (depending on choice 2 above) - left click properties
inside the "start in" text box paste the location of your default start directory
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
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
HKEY_CURRENT_USER\Software\Microsoft\Command Processor
string: Autorun
value: cd /d %~dp0
all bat files will run from the bat file location
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.
go to regedit ( go to search and type regedit)
expand "HKEY_CURRENT_USER" node
under HKEY_CURRENT_USER node expand "software" node
under software node expand "microsoft" node
under microsoft node click on "Command Processor"
path looks like this : "HKEY_CURRENT_USER\Software\Microsoft\Command Processor"
it looks something like this :
if you do not see "Autorun" String Value
Right Click - New - Expandable String Value, and rename it to Autorun
double click on "Autorun"
10.enter this value path format:
"CD/d C:\yourfoldername\yoursubfoldername"
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"
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:
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
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.
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"
},
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)
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.
"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 ;)
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 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.
Related
I am usually working within the same directory (or subfolders of it) and it has quite a long path so it would be really convenient if my command prompt automatically started in that directory (instead of C:\Users\username). How can I change the starting folder to the one I want?
There are two main ways to do it:
Create a shortcut that opens CMD in the directory you want (recommended).
Create a Command Prompt shortcut
Access the properties of the shortcut and set the path where you want it to open in the "Start in" field
Change the path that the command prompt uses by default
Open regedit
Go to "Computer\HKEY_CURRENT_USER\Software\Microsoft\Command Processor"
Create a new "String Value" with the name "Autorun" and with the value "cd /d C:\EXAMPLEDIR"
I use address bar of File explorer to open command prompt in current directory(By typing cmd in address bar). It will open the command prompt as Administrator. I have used Windows 7 OS and I logged in as Domain Administrator.
Now I upgraded the OS to Windows 10. Now I am doing the same, But command prompt is not opened as Administrator.(For local Administrator account it was fine). Is there any way to get command prompt as Administrator(Opening from Address bar) ?
We can add this windows default shortcut for achieving cmd as Administrator in single click
Unfortunately a recent Windows 10 Update has removed the Open command prompt mentioned by #Arvindharaj. However, if you feel comfortable editing the Windows Registry then this site that explains how to activate admin cmd right-click option might be a great option. It was for me.
Here are basic steps after launching regedit.exe:
Go to this address: HKEY_CLASSES_ROOT\Directory\shell
Under this folder create a new key and label it runas.
Double-click the runas folder and check if there’s a “Default” key. Right-click it and choose “Modify.”
Once you click “Modify,” the “Edit String” box shows up. Type Open Administrator Command Prompt Here in the Value data box.
Next, in the same folder, create a new string value (right-click the runas folder and choose New and select String Value). Label it as NoWorkingDirectory.
Under the HKEY_CLASSES_ROOT\Directory\shell\runas path, create another key and label it as command.
Double click the folder and you’ll see the Default string value. Right click and choose “Modify.” Under the Value data, enter cmd.exe /k cd %1 and click OK.
FYI - I think this last step is wrong btw. The cmd prompt will launch as admin but in its default folder. So instead enter "cmd.exe /s /k pushd %V" and this should launch the admin prompt in the folder you right-clicked on.
I've tried #Alex's solution, but it still didn't work, CMD still evaluated without Administrator privileges.
I only have it working after running the following command in command prompt:
> REG ADD HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System
/v EnableLUA /t REG_DWORD /d 0 /f
And restart the Computer after this.
Can't say that this only helps, but maybe this in addition to #Alex's did the job.
Adding up to response from Aravindharaj G :
1> In File Explorer go to the window where you want to open PowerShell / Command Prompt
Use HotKey ( ALT (Hold) + F > S > A ) will open PS in that location.
2> Using Top Menu File > Open Command Prompt ( or Open Window PowerShell ) > Open Command Prompt as Administrator > now SELECT
"Add to Quick Access Toolbar"
This will add a Tiny icon in all File Explorer Windows for all.
Is it possible to create a desktop shortcut that, when pressed, will open command prompt and run a pre-defined command?
Create A Shortcut That Opens The Command Prompt & Runs A Command:
Yes! You can create a shortcut to cmd.exe with a command specified after it. Alternatively you could create a batch script, if your goal is just to have a clickable way to run commands.
Steps:
Right click on some empty space in Explorer, and in the context menu go to "New/Shortcut".
When prompted to enter a location put either:
"C:\Windows\System32\cmd.exe /k your-command" This will run the command and keep (/k) the command prompt open after.
or
"C:\Windows\System32\cmd.exe /c your-command" This will run the command and the close (/c) the command prompt.
Notes:
Tested, and working on Windows 8 - Core X86-64 September 12 2014
If you want to have more than one command, place an "&" symbol in between them. For example: "C:\Windows\System32\cmd.exe /k command1 & command2".
Yes, make the shortcut's path
%comspec% /k <command>
where
%comspec% is the environment variable for cmd.exe's full path, equivalent to C:\Windows\System32\cmd.exe on most (if not all) Windows installs
/k keeps the window open after the command has run, this may be replaced with /c if you want the window to close once the command is finished running
<command> is the command you wish to run
The solutions turned out to be very simple.
Open text edit
Write the command, save as .bat.
Double click the file created and the command automatically starts running in command-prompt.
Create new text file on desktop;
Enter desired commands in text file;
Rename extension of text file from ".txt" --> ".bat"
Yes. One option you have is to create a batch file containing the command
cmd -c {your command}
or
cmd -k {your command}
The shortcut will then be to this batch file.
This is an old post but I have issues with coming across posts that have some incorrect information/syntax...
If you wanted to do this with a shorcut icon you could just create a shortcut on your desktop for the cmd.exe application. Then append a /K {your command} to the shorcut path.
So a default shorcut target path may look like "%windir%\system32\cmd.exe", just change it to %windir%\system32\cmd.exe /k {commands}
example: %windir%\system32\cmd.exe /k powercfg -lastwake
In this case i would use /k (keep open) to display results.
Arlen was right about the /k (keep open) and /c (close)
You can open a command prompt and type "cmd /?" to see your options.
http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/cmd.mspx?mfr=true
A batch file is kind of overkill for a single command prompt command...
Hope this helps someone else
I tried this, all it did was open a cmd prompt with "cmd -c (my command)"
and didn't actually run it. see below.
C:\windows\System32>cmd -c (powercfg /lastwake)
Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation. All rights reserved.
C:\windows\System32>
***Update
I changed my .bat file to read "cmd /k (powercfg /lastwake)" and it worked.
You can also leave out the () and it works too.
You can also create a shortcut on desktop that can run a specific command or even a batch file by just typing the command in "Type the Location of Item" bar in create shortcut wizard
Right click on Desktop.
Enter the command in "Type the Location of Item" bar.
Double click the shortcut to run the command.
Found detailed Instructions here
Using the Drag and Drop method
From the windows search bar type in cmd to pull up the windows bar operation.
When the command line option is shown, right click it and select Open File Location.
The file explorer opens and the shortcut link is highlighted in the folder. If it is not highlighted, then select it.
Hold down the Control key and using the mouse drag the shortcut to the desktop. If you don't see Copy to Desktop while dragging and before dropping, then push down and hold the Control key until you see the message.
Drop the link on the desktop.
Change properties as needed.
I have many scripts which I interact with from the command line. Everytime I need to use them, I have to open a command line window and copy+paste and CD to the path to the directory they are in. This is tedious (they are in a rather deep file system, so typing out the full path is a pain, copy+paste is better but not much). I tried to create a .BAT file that I could double-click on that would open a new command-line window in the folder the .bat file exists in but it does not work. It opens a new window, but the working directory is not the directory that .bat file is in. Here's what I've got after much googling (My cmd skills ain't so great):
cd %CD%
cmd.exe
I know from when I used Linux that Konqueror had a "Command-line window here" feature, and that's the effect I'm trying to get on Windows.
you probably want to do this:
cd /d %~dp0
cmd.exe
this will set your current directory to the directory you have the batch file in
Create a file named open_dos_here.cmd with the following lines:
%~d1
cd "%~p1"
call cmd
Put this file at any folder.
Then, go to your Send To folder (Win+E; Alt+D;shell:sendto;Enter).
Create a shortcut to point to this open_dos_here.cmd
Then, in any folder, select any file or sub-folder. Right-click and select "Send To" and then select open_dos_here.cmd to open the DOS in that folder.
You can just enter cmd into the address bar in Explorer and it starts up in that path. Likewise for PowerShell.
There's a simpler way -
start /d "folder path"
As a more general solution you might want to check out the Microsoft Power Toy for XP that adds the "Open Command Window Here" option when you right-click: http://www.microsoft.com/windowsxp/downloads/powertoys/xppowertoys.mspx
In Vista and Windows 7, you'll get that option if you hold down shift and right-click (this is built in).
I'm thinking that if you are creating a batch script that relies on the Current Directory being set to the folder that contains the batch file, that you are setting yourself up for trouble when you try to execute the batch file using a fully qualified path as you would from a scheduler.
Better to add this line to your batch file too:
REM Change Current Directory to the location of this batch file
CD /D %~dp0
unless you are fully qualifying all of your paths.
Another solution is to use a shortcut file to cmd.exe instead of a batch file.
Edit the shortcut's start in property to %~dp0.
You achieve the same thing, except it has the Cmd icon (and you can change this).
Some people don't like clicking on batch files without knowing what's in them, and some corporate network drives have a ban on .bat files...
The simplest command to do this:
start
You can always run this in command line to open new command line window in the same location. Or you can place it in your .bat file.
Most simple way in explorer is to Shift + right mouse click on the folder or on an empty space in the folder and click on Open command prompt here.
CMD will then start in that folder
I must say, I'm not sure if it works for Windows Vista and below, but it surely works for Windows 7, 8, 8.1 and 10.
Referring to answer of #Chris,
We can also go to parent directory of batch file and run commands using following
cd /d %~dp0..
<OTHER_BATCH_COMMANDS>
cmd.exe
To understand working of command cd /d %~dp0.. please refer below link
What does it mean by command cd /d %~dp0 in Windows
You could add a context menu entry through the registry:
Navigate in your Registry to
HKEY_LOCAL_MACHINE/Software/Classes/Folder/Shell
and create a key called "Command Prompt" without the quotes.
Set the default string to whatever text you want to appear in the right-click menu.
Create a new key within your newly created command prompt named "command," and set the default string to
cmd.exe /k pushd %1
You may need to add %SystemRoot%\system32\ before the cmd.exe if the executable can't be found.
The changes should take place immediately. Right click a folder and your new menu item should appear.
Also see http://www.petri.co.il/add_command_prompt_here_shortcut_to_windows_explorer.htm
When you are in the desired folder , just type CMD in your address bar
A bit late to the game but if I'm understanding your needs correctly this will help people with the same issue.
Two solutions with the same first step:
First navigate to the location you keep your scripts in and copy the filepath to that directory.
First Solution:
Click "Start"
Right-click "Computer" (or "My Computer)
Click "Properties"
On the left, click "Advanced System Settings"
Click "Environment Variables"
In the "System Variables" Box, scroll down and select "PATH"
Click "Edit"
In the "Variable Value" field, scroll all the way to the right
If there isn't a semi-colon (;) there yet, add it.
Paste in the filepath you copied earlier.
End with a semi-colon.
Click "OK"
Click "OK" again
Click "OK" one last time
You can now use any of your scripts as if you were already that folder.
Second Solution: (can easily be paired with the first for extra usefulness)
On your desktop create a batch file with the following content.
#echo off
cmd /k cd "C:\your\file\path"
This will open a command window like what you tried to do.
For tons of info on windows commands check here: http://ss64.com/nt/
Create a new file startCmdLine.bat in your directory and put this line in it
call cmd
That is it. Now double click on the .bat file. It works for me.
You can replace call with start, it will also work.
this code works for me
name it cmd.bat
#echo off
title This is Only A Test
echo.
:Loop
set /p the="%cd%"
%the%
echo.
goto loop
you can try:
shift + right click
then, click on Open command prompt here
Inside given folder click on the top Adddress Bar and type cmd and click enter
It will open command prompt with current folder address.
You can simply create a bat file in any convenient place and drop any file from the desired directory onto it.
Haha. Code for this:
cmd
I have a shortcut on my desktop which opens a command prompt with many arguments that I need. I set the 'start in' field to d:\ and it works as expected (the prompt starts in d:). When I choose Advanced -> run as administrator and then open the shortcut, it starts in C:\Windows\System32, even though I have not changed the 'start in' field. How can I get it to start in d:\?
If you use the /k argument, you can add a single line to execute a change drive and change directory. For instance:
C:\Windows\System32\cmd.exe /k "d: & cd d:\storage"
Using & you can string together many commands on one line.
Edit: You can also change drive with the cd command alone "cd /d d:\storage". Thanks to Adam Mitz for the comment.