Related
It happens again and again that I am in a Powershell session and want to execute a command for which I need admin (elevated) rights.
My current workflow then:
1. pwd (ctrl+c)
2. open a new Powershell (run as administrator)
3. cd ctrl+v
This is very annoying and time-consuming, how can I optimise this?
I guess the standard way of creating a shortcut should do it:
In a command box type where wt.exe to get the file path.
This will most probably return C:\Users\<yourname>\AppData\Local\Microsoft\WindowsApps\wt.exe
Open the path and right-click wt.exe (eventhough in there it shows 0 kb)
Select 'Create Shortcut'
Right-click the new shortcut and in the General tab change the name to Windows Terminal (Admin)
In the Shortcut tab, click the Advanced button and check the box "Run as administrator"
click OK
Drag the shortcut to your desktop
Theo's answer didn't work for me, but this one did. Copied:
Right click -> New -> Shortcut
Type in C:\Windows\System32\cmd.exe /c start /b %USERPROFILE%\AppData\Local\Microsoft\WindowsApps\wt.exe for the location
Give whatever name you want to give, finish.
List item
Right click on the newly created shortcut -> Properties -> Advanced -> Run as administrator
I have a project folder somewhere, and many times I need to open command prompt (on windows 7/8.1/10) and cd to that folder. It would be very handy if there's an option right click > open cmd here.
is there a tool for that?
Just go to your folder location and type "cmd" on the address bar.
Press Shift + Menu, then choose Open Command Window Here. It works.
In win7/8, try right click while holding shift key, should have cmd prompt here
How about to use the PowerShell OpenHere module?
Run PowerShell with elevated permissions and type:
Install-Module OpenHere; Import-Module OpenHere
Set-OpenHereShortcut -ShortcutType:WindowsPowerShell
Disclaimer:
I'm a developer of this module.
use the description in https://stackoverflow.com/a/34534874/1498669 and put "run as administrator" checkbox on
Open 'File Explorer' and enter "shell:sendto" in location bar + hit return to get into this folder
Right mouse click and create a "New"->"Shortcut", put cmd.exe into the path, done
Edit the properties of the shortcut and edit the target to "%windir%\system32\cmd.exe /k pushd"
you can also create a copy of that shortcut, rename it to cmd.exe_admin, select properties, hit button "Advanced" an select the checkbox "run as Administrator"
Now use the "SendTo"-submenu in the explorer right click context menu to send any filepath or folder into the normal or elevated commandbox.
This "shell:sendto"-trick is also very useful for eg. Notepad++ or any program you want to start in "elevated" mode.
Type cmd command in address bar where path or location of the file or folder is shown.
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.
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.
How can I open a cmd window in a specific location without having to navigate all the way to the directory I want?
This might be what you want:
cmd /K "cd C:\Windows\"
Note that in order to change drive letters, you need to use cd /d. For example:
C:\Windows\System32\cmd.exe /K "cd /d H:\Python\"
(documentation)
Assuming that in File Explorer you have opened the target directory/folder, do this:
Click on address bar, alternatively press Alt+D
Now when address bar is highlighted, type cmd in the bar.
Press Enter key
You will notice that command prompt from that folder
If you have Windows Vista or later, right-click on the folder icon in Explorer while holding the Shift key, and then click on the "Open command window here" or "Open PowerShell window here" context menu option.
If you're already in the folder you want, you can do one of the following:
[only Win8+] Click the Explorer Ribbon's File button, then click on "Open command window here" or "Open PowerShell window here".
Shift-right-click on the background of the Explorer window, then click on "Open command window here" or "Open PowerShell window here". (recommended by Kate in the comments)
[only Vista or Win7] Hold down Shift when opening the Explorer File menu, then click on "Open command window here". If you can't see the menu bar, open the File menu by pressing Alt-Shift-F - Alt-F to open the File menu, plus Shift.
For Windows XP, use the PowerToy mentioned by dF to get the same function.
From Windows 7 up to some versions of Windows 10, it is very simple to open a command prompt anywhere you wish, without navigation using command "cd".
Try the following one.
Click the mouse's right button by holding Shift key .
It will produce an option like this. Then simply select the "Open command window here " option.
The latest versions of Windows 10 have replaced this feature with "Open Powershell here".
Try out this "PowerToy" from Microsoft:
Open Command Window Here
This PowerToy adds an "Open Command
Window Here" context menu option on
file system folders, giving you a
quick way to open a command window
(cmd.exe) pointing at the selected
folder.
EDIT : This software will not work on any version of Windows apart from Windows XP.
On Windows Vista, Windows 7 and Windows 10 simply hold down the Shift key and right-click on a folder.
The context menu will contain an entry titled: "Open command window here"
Update: Type "cmd" in the address bar of Explorer and press enter
Update 2: In windows 10, go to file menu and select "Open Windows PowerShell". There is an option for running as administrator.
Update 3: You can also add a quick access shortcut by going to file menu, right click on "Open windows Powershel" and select "Add to Quick Access Toolbar" and after that with one single click you can access the powershell immediately
Use the /K switch. For example
cmd /K "cd /d c:\WINDOWS\"
Will create a cmd window at the C:\Windows directory
Just write cmd in the address bar, it will open in the current folder.
In windows go to folder location in file explorer remove path and type cmd and press enter. and path will open in cmd.
Also, here is a shortcut to open a console in any windows folder:
Open any folder on windows explorer.
Press Alt + D to focus the adress bar
type cmd and press enter
Very practical shortcut.
pushd command sets the current folder. so:
cmd /k "pushd D:\Music"
In Windows 8, you can click the address bar and type "cmd" (without quotes) and hit enter. This will open the cmd window in the current path.
Easiest way is to goto the address bar of the Windows Explorer and type cmd there. It will automatically open the command prompt window for you.
If you are starting cmd from taskbar, this is what you need to do:
right click --> rightclick on Command Prompt --> Properties
Then in the properties window change the value of Start in:
This solution doesn't work for opening command prompt as administrator
Create a shortcut and edit the "Start In" property of the shortcut to the directory you want the cmd.exe to start in.
I just saw this question and cannot help to post my AutoHotkey script for cmd on Windows XP. You can spot the hot keys in the script. The nice thing is when your current windows is Explorer, the cmd will open in the path showing in the address bar.
I keep this script in a folder where I store all green tools (including AutoHotkey). For a new machine, I just copy the folder, double click the script to associate .ahk with AutoHotkey and create a shortcut in my startup folder. It is faster than installing PowerToys.
; Get working folder
GetWorkingFolder() {
if WinActive("ahk_class ExploreWClass") or WinActive("ahk_class CabinetWClass") {
ControlGetText, path, Edit1
return %path%
} else if WinActive("FreeCommander") {
Send, {CTRLDOWN}{ALTDOWN}{INS}{ALTUP}{CTRLUP}
Sleep, 100
return clipboard
} else {
return "C:\"
}
}
#IfWinActive,
#c::
path := GetWorkingFolder()
Run, %ComSpec%, %path%
return
; PowerShell
#+C::
path := GetWorkingFolder()
Run, %SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe, %path%
return
#^c::
Run, %ComSpec%, %temp%
return
#!c::
path := GetWorkingFolder()
Run, %comspec% /k "%VS90COMNTOOLS%vsvars32.bat", %path%
return
; irb
#!b::
path := GetWorkingFolder()
Run, c:\cygwin\bin\ruby /usr/bin/irb, %path%
return
; Bash
#b::
path := GetWorkingFolder()
Run, bash --login, %path%
return
; Paste in console
+INS::
if WinActive("ahk_class ConsoleWindowClass") {
WinGetPos, x, y, w, h, A
MouseGetPos, mx, my
;MsgBox x=%x% y=%y% w=%w% h=%h% mx=%mx% my=%my%
if (mx < 10)
mx = 10
else if (mx > w - 30)
mx := w - 30
if (my < 40)
my = 40
else if (my > h)
my := h - 10
MouseClick, right, mx, my
}
return
For anyone who is interested, you can find this script at rwin on github
This will add entries to the context-menu to launch a command window that is automatically navigated to the directory you clicked.
Usage:
Right-click a folder icon (or the empty background area inside an already open folder)
and click either "Open in Terminal" or "Open in Terminal (Admin)".
You can also right click files to execute them with a command window.
When the file is done running you are left with a command window that is navigated to the files directory.
Open_in_Terminal.reg
Windows Registry Editor Version 5.00
; Admin versions.
; Right click on a folder in a directory.
[HKEY_CLASSES_ROOT\Directory\shell\OpenCommandWindowHereAsAdministrator]
#="Open in Terminal (Admin)"
"Icon"="cmd.exe"
"HasLUAShield"=""
"Position"="middle"
[HKEY_CLASSES_ROOT\Directory\shell\OpenCommandWindowHereAsAdministrator\command]
#="cmd.exe /c powershell.exe -Command \"Start-Process cmd -Verb runas -ArgumentList '/k pushd \"%1\"'\""
; Right click on nothing in a directory, i.e. the "background" of the directory.
[HKEY_CLASSES_ROOT\Directory\Background\shell\OpenCommandWindowHereAsAdministrator]
#="Open in Terminal (Admin)"
"Icon"="cmd.exe"
"HasLUAShield"=""
"Position"="middle"
[HKEY_CLASSES_ROOT\Directory\Background\shell\OpenCommandWindowHereAsAdministrator\command]
#="cmd.exe /c powershell.exe -Command \"Start-Process cmd -Verb runas -ArgumentList '/k pushd \"%V\"'\""
; Right click on nothing in a library directory, i.e. the "background" of the library directory.
[HKEY_CLASSES_ROOT\LibraryFolder\Background\shell\OpenCommandWindowHereAsAdministrator]
#="Open in Terminal (Admin)"
"Icon"="cmd.exe"
"HasLUAShield"=""
"Position"="middle"
[HKEY_CLASSES_ROOT\LibraryFolder\Background\shell\OpenCommandWindowHereAsAdministrator\command]
#="cmd.exe /c powershell.exe -Command \"Start-Process cmd -Verb runas -ArgumentList '/k pushd \"%V\"'\""
; Right click on a file in a directory.
[HKEY_CLASSES_ROOT\*\shell\OpenWithCommandWindowAsAdministrator]
#="Open in Terminal (Admin)"
"Icon"="cmd.exe"
"HasLUAShield"=""
"Position"="middle"
[HKEY_CLASSES_ROOT\*\shell\OpenWithCommandWindowAsAdministrator\command]
#="cmd.exe /c powershell.exe -Command \"Start-Process cmd -Verb runas -ArgumentList '/k pushd \\\"%W \\\" && \\\"%1\\\"'\""
; Non-Admin versions.
; Right click on a folder in a directory.
[HKEY_CLASSES_ROOT\Directory\shell\OpenCommandWindowHere]
#="Open in Terminal"
"Icon"="cmd.exe"
"Position"="middle"
[HKEY_CLASSES_ROOT\Directory\shell\OpenCommandWindowHere\command]
#="cmd.exe /k pushd \"%1\""
; Right click on nothing in a directory, i.e. the "background" of the directory.
[HKEY_CLASSES_ROOT\Directory\Background\shell\OpenCommandWindowHere]
#="Open in Terminal"
"Icon"="cmd.exe"
"Position"="middle"
[HKEY_CLASSES_ROOT\Directory\Background\shell\OpenCommandWindowHere\command]
#="cmd.exe /k pushd \"%V\""
; Right click on nothing in a library directory, i.e. the "background" of the library directory.
[HKEY_CLASSES_ROOT\LibraryFolder\Background\shell\OpenCommandWindowHere]
#="Open in Terminal"
"Icon"="cmd.exe"
"Position"="middle"
[HKEY_CLASSES_ROOT\LibraryFolder\Background\shell\OpenCommandWindowHere\command]
#="cmd.exe /k pushd \"%V\""
; Right click on a file in a directory.
[HKEY_CLASSES_ROOT\*\shell\OpenWithCommandWindow]
#="Open in Terminal"
"Icon"="cmd.exe"
"Position"="middle"
[HKEY_CLASSES_ROOT\*\shell\OpenWithCommandWindow\command]
#="cmd.exe /k pushd \"%W\" && \"%1\""
This took a lot of effort to make so if you're feeling generous then feel free to send a paypal donation to help me overcome the PTSD of debugging and testing it :)
An uninstaller if you need one:
Open_in_Terminal_Remover.reg
Windows Registry Editor Version 5.00
[-HKEY_CLASSES_ROOT\Directory\shell\OpenCommandWindowHereAsAdministrator]
[-HKEY_CLASSES_ROOT\Directory\Background\shell\OpenCommandWindowHereAsAdministrator]
[-HKEY_CLASSES_ROOT\LibraryFolder\Background\shell\OpenCommandWindowHereAsAdministrator]
[-HKEY_CLASSES_ROOT\*\shell\OpenWithCommandWindowAsAdministrator]
[-HKEY_CLASSES_ROOT\Directory\shell\OpenCommandWindowHere]
[-HKEY_CLASSES_ROOT\Directory\Background\shell\OpenCommandWindowHere]
[-HKEY_CLASSES_ROOT\LibraryFolder\Background\shell\OpenCommandWindowHere]
[-HKEY_CLASSES_ROOT\*\shell\OpenWithCommandWindow]
Update: This is built into Windows now. See this answer.
The XP powertoy is a good option, but I thought I'd post another, in case you'd like to "roll your own". Create a text file, name it anything.reg, paste in the code below, save it, then double-click on it to add it to the registry (or just add the info to the registry manually if you understand what's going on in this .reg file).
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\Folder\shell\Command_Prompt_Here...]
#="Command Prompt Here..."
[HKEY_CLASSES_ROOT\Folder\shell\Command_Prompt_Here...\command]
#="cmd.exe \"%1\""
Update: After an Windows-update, Win10 removed the cmd-here feature. To reactivate it you've to use:
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\Directory\shell\cmd]
#="#shell32.dll,-8506"
"Extended"=""
"NoWorkingDirectory"=""
"ShowBasedOnVelocityId"=dword:00639bc8
[HKEY_CLASSES_ROOT\Directory\shell\cmd\command]
#="cmd.exe /s /k pushd \"%V\""
The entry ShowBasedOnVelocityId is mandatory
This answer is for windows 10.
Create a command prompt shortcut in the folder wherever you want, then right click on that shortcut
and
For windows 7 or later, inside the target folder address bar just type cmd. That is it. It will open up command prompt with path set to your present directory.
In File Explorer, press and hold the Shift key, then right click or press and hold on a folder or drive that you want to open the command prompt at that location for, and click/tap on Open Command Prompt Here option.
I see that there are multiple answers, some are quite complex :) , strange to see them. You just have to open any windows folder window, navigate to your desired folder and focus on address bar and enter "cmd" and press enter, you would be presented with new command prompt window directly with the folder path or location that we already navigated in windows folder window.
In case you want to see these steps with clear images you can check out
how to open command prompt in a specific folder directly
Make the shortcut to cmd.exe with params /S /K pushd "C:\YOUR FOLDER\"
For windows :
Select the folder which you want to open in command prompt - After selection,
Keeping the 'Shift key' pressed. Right click there and choose option
"open command window here"
In Windows go to the specific folder, then click on the file explorer path and remove it then type cmd and click enter.. and in cmd your specific folder with its path will open..
In Windows Explorer - shift + right mouse click above folder "Open command window here" option show up in the menu. Or in language of your Windows version.
<===||==========> On Windows 10 <==========||===>
Assuming that in File Explorer you have opened the target directory/folder, do this :
Click on address bar, alternatively press Alt + A
Now when address bar is highlighted, type cmd in the bar.
Press Enter key
For a powershell window :
Just press Alt + f + s + a
There is a simplier way I know. Find cmd.exe in start menu and send it to Desktop as shortcut. Then right-click it and choose properties. You will see "Start in" box under the "Target". Change that directory as whatever you'd like to set. Click OK and start cmd.exe which is in your Desktop. In my opinion, it's a very easy and certain solution :)
This program always opens cmd.exe in the current path of your Explorer:
https://github.com/jhasse/smart_cmd
You can also pin it to your taskbar and then use WindowsKey+[1-0] as a keyboard shortcut.
If you use Total Commander there is a field in the bottom for this. It shows the active directory you are currently in and will run the entered command in that directory.