Is there a way to start PowerShell in a specific folder from Windows Explorer, e.g. to right-click in a folder and have an option like "Open PowerShell in this Folder"?
It's really annoying to have to change directories to my project folder the first time I run MSBuild every day.
In Windows Explorer, just go to the Address Bar at the top (keyboard shortcuts: Alt+D or Ctrl+L) and type powershell or powershell_ise and press Enter. A PowerShell command window opens with the current directory.
Just to add in the reverse as a trick, at a PowerShell prompt you can do:
ii .
or
start .
to open a Windows Explorer window in your current directory.
If you're on Windows 8, or later, you can simply use the built-in File → "Open Windows PowerShell".
Or Alt + F followed by R.
As an alternative to the answer above, which requires you to type the PowerShell command (powershell.exe) each time, you can create a context menu entry just like with the "Open command window here" context menu.
There are three registry keys where these commands go. Each key controls the context menu of a different Windows Explorer object. The first one is the one you asked about:
HKCR\Directory\Background\shell - This is the context menu for the Explorer window itself (that is, the context menu that is displayed when no item is selected, such as when right-clicking in an empty area of the window).
HKCR\Directory\shell - This is the context menu of the folders in Windows Explorer.
HKCR\Drive\shell - This is the context menu for the drive icons in the root of Windows Explorer.
For each of these registry keys, you can add a subkey that will add an "Open PowerShell window here" command to the context menu, just as you have an "Open command window here" context menu.
Here is a copy of my OpenPowerShellHere.reg file, which puts the command in the context menu of each of the Explorer objects, the window background, the folder, and the drive icon:
Windows Registry Editor Version 5.00
;
; Add context menu entry to Windows Explorer background
;
[HKEY_CLASSES_ROOT\Directory\Background\shell\powershell]
#="Open PowerShell window here"
"NoWorkingDirectory"=""
[HKEY_CLASSES_ROOT\Directory\Background\shell\powershell\command]
#="C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe -NoExit -Command Set-Location -LiteralPath '%V'"
;
; Add context menu entry to Windows Explorer folders
;
[HKEY_CLASSES_ROOT\Directory\shell\powershell]
#="Open PowerShell window here"
"NoWorkingDirectory"=""
[HKEY_CLASSES_ROOT\Directory\shell\powershell\command]
#="C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe -NoExit -Command Set-Location -LiteralPath '%V'"
;
; Add context menu entry to Windows Explorer drive icons
;
[HKEY_CLASSES_ROOT\Drive\shell\powershell]
#="Open PowerShell window here"
"NoWorkingDirectory"=""
[HKEY_CLASSES_ROOT\Drive\shell\powershell\command]
#="C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe -NoExit -Command Set-Location -LiteralPath '%V'"
So, with your favorite text editor, open a new file named OpenPowerShellHere.reg. Copy the exact text of the code above, paste it into the new file, and save it. (I would have included a copy of the file, but I couldn't figure out if attachments were possible.) If you want to exclude the command from one of the entry, just comment out the appropriate section with semicolons. My comments show you each section.
After you save the file, run it by double-clicking on it. When it asks, tell it to proceed. As soon as you run it, the context menu entries will show up!
Here is my Explorer window context menu. I've highlighted the console and PowerShell commands. As you can see, you can also add a context menu entry to run an elevated command window, i.e., Run as Administrator.
Note: Context menu entries are displayed alphabetically, based on their Registry keys. The key name for the elevated command shell is "runas", which is why it comes after the PowerShell entry.
Note: If you have an explorer window open, you may need to close it and reopen it to get the changed to take effect.
Note: In Windows 7, the HKCR\Directory\Shell does not work if you use the toolkit on the side of the explorer
(ie. Clicking Documents under the Libraries header)
you must navigate using Computer -> C: -> to -> Some -> Target -> Directory
You can download the inf file from here - Introducing PowerShell Prompt Here
In Windows 10 both the command prompt and the powershell prompt can be found via the menu bar, for both non-admin and admin. These options will have its folder set to the currently selected folder from the explorer.
For the Swedish version at least, the powershell is opened with Alt F+I. For an administrator powershell it's Alt F+S+P.
If those are not the correct characters you can press and hold the Alt key to see the correct characters. there will be a character overlaying the menu item for each step.
I'm surprised nobody has given this answer, it's the simplest one. (Must be the year.)
Just Shift + right click in Explorer. Then you can "Open PowerShell window here".
It may be set to Command Prompt by default. If so, you can change this in the Windows 10 Settings: go to Personalization -> Taskbar and enable "Replace Command Prompt with Windows PowerShell in the menu when I right-click the start button or press Windows key+X".
Windows 10 made it much easier. You can either:
SHIFT + Mouse Right Click on a folder, and you get a menu item Open PowerShell window here.
Or you can:
File -> Open Windows PowerShell.
And for a bonus ...
If you Mouse Right Click on File -> Open Windows PowerShell, then you can Add to Quick Access Toolbar:
Which puts a handy icon here:
And now you can just click that icon. :)
I wanted to have this context menu work only when right clicking and holding the 'SHIFT' which is how the built in 'Open Command window here' context menu works.
However none of the provided solutions did that so I had to roll my own .reg file - copy the below, save it as power-shell-here-on-shift.reg and double click on it.
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\Directory\shell\powershell]
#="Open PowerShell here"
"NoWorkingDirectory"=""
"Extended"=""
[HKEY_CLASSES_ROOT\Directory\shell\powershell\command]
#="C:\\Windows\\system32\\WindowsPowerShell\\v1.0\\powershell.exe -NoExit -Command Set-Location -LiteralPath '%L'"
Try the PowerShell PowerToy... It adds a context menu item for Open PowerShell Here.
Or you could create a shortcut that opens PowerShell with the Start In folder being your Projects folder.
In the more recent versions, Windows 10 has "Open PowerShell window here" by default in the context menu when you Shift+Mouse Right Click on an empty space, and you should be using Windows Terminal by now anyway.
It's even easier in Windows 8.1 and Server 2012 R2.
Do this once:
Right-click on the task bar, choose Properties. In the Navigation tab, turn on [✓] Replace Command Prompt with Windows PowerShell in the menu when I right-click the lower-left corner or press Windows key+X.
Then whenever you want a PowerShell prompt, hit Win+X, I. (Or Win+X, A for an Admin PowerShell prompt)
There's a Windows Explorer extension made by the dude who makes tools for SVN that will at least open a command prompt window.
I haven't tried it yet, so I don't know if it'll do PowerShell, but I wanted to share the love with my Stack Overflow brethren:
http://tools.tortoisesvn.net/StExBar
Another option are the excellent Elevation PowerToys by Michael Murgolo on TechNet at http://technet.microsoft.com/en-us/magazine/2008.06.elevation.aspx.
They include PowerShell Prompt Here and PowerShell Prompt Here as Administrator.
By adding the registry keys below, in Windows 10, I managed to get the Open PowerShell Here option in my SHIFT + RClick context menus.
Just copy these into a blank notepad file then save as a .reg file and run the file to add the key and it should work from there.
Some of these other answers say to add the key into HKCR\Directory\shell but I found that for me it only worked with the keys going into HKLM\SOFTWARE\Classes\Directory\shell
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Directory\background\shell\powershell]
"Extended"=""
"NoWorkingDirectory"=""
#="Open PowerShell here"
"Icon"="%SystemRoot%\\system32\\WindowsPowerShell\\v1.0\\powershell.exe"
[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Directory\background\shell\powershell\command]
#="C:\\Windows\\system32\\WindowsPowerShell\\v1.0\\powershell.exe -NoExit -Command Set-Location -LiteralPath '%V'"
[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Directory\shell\powershell]
#="Open PowerShell here"
"Extended"=""
"Icon"="%SystemRoot%\\system32\\WindowsPowerShell\\v1.0\\powershell.exe"
"NoWorkingDirectory"=""
[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Directory\shell\powershell\command]
#="C:\\Windows\\system32\\WindowsPowerShell\\v1.0\\powershell.exe -NoExit -Command Set-Location -LiteralPath '%V'"
New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT
if(-not (Test-Path -Path "HKCR:\Directory\shell\$KeyName"))
{
Try
{
New-Item -itemType String "HKCR:\Directory\shell\$KeyName" -value "Open PowerShell in this Folder" -ErrorAction Stop
New-Item -itemType String "HKCR:\Directory\shell\$KeyName\command" -value "$env:SystemRoot\system32\WindowsPowerShell\v1.0\powershell.exe -noexit -command Set-Location '%V'" -ErrorAction Stop
Write-Host "Successfully!"
}
Catch
{
Write-Error $_.Exception.Message
}
}
else
{
Write-Warning "The specified key name already exists. Type another name and try again."
}
You can download detail script from how to start PowerShell from Windows Explorer
One fairly simple alternative is to invoke PowerShell via a shortcut. There is a shortcut property labeled "Start in" that says what directory(folder) to use when the shortcut is invoked.
If the Start In box is blank, it means use the current directory.
When you first create a shortcut to PowerShell in the usual way, the start in box specifies the home directory. If you blank out the start in box, you now have a shortcut to powershell that opens PS in the current directory, whatever that is.
If you now copy this shortcut to the target directory, and use explorer to invoke it, you'll start a PS that's pointed at the target directory.
There's already an accepted answer to this question, but I offer this as another way.
For autohotkey users, heres a snippet I am using
It opens PowerShell window, when pressing Ctrl-Alt-T. (Tested with Win10)
If your "active window" is a Windows Explorer -window, then the PowerShell is opened in the current folder. Otherwise, just open PowerShell in some default folder.
Usage: 1) Install AutoHotkey, and copy paste this into myscript.ahk 2) Replace <DefaultPath> with path of your choice. 3) Run the script.
; Ctrl-Alt-T opens PowerShell in the current folder, if using Windows Explorer. Otherwise, just open the Powershell.
^!T::
if WinActive("ahk_class CabinetWClass") and WinActive("ahk_exe explorer.exe")
{
KeyWait Control
KeyWait Alt
Send {Ctrl down}l{Ctrl up}
Send powershell{Enter}
}
else
{
psScript =
(
cd 'C:\<DefaultPath>'
ls
)
Run "%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe" -NoExit -Command &{%psScript%}
}
return
I created a fully automated solution to add PS and CMD context items.
Just run set_registry.cmd and it will update registry to add two buttons when click RMB on folder or inside some opened folder:
This will change owner of registry keys to admin and add context menus
Change registry to enable PS and CWD context menus
Only this worked for me on Windows 10...
Create a file named PowershellHereContextMenu.reg with the contents below, right click on it and "Merge".
Windows Registry Editor Version 5.00
;
; Add context menu entry to Windows Explorer folders
;
[HKEY_CLASSES_ROOT\Directory\shell\powershellmenu]
#="PowerShell Here"
[HKEY_CLASSES_ROOT\Directory\shell\powershellmenu\command]
#="C:\\\\Windows\\\\system32\\\\WindowsPowerShell\\\\v1.0\\\\powershell.exe -NoExit -Command Set-Location -LiteralPath '%L'"
;
; Add context menu entry to Windows Explorer background
;
[HKEY_CLASSES_ROOT\Directory\Background\shell\powershellmenu]
#="PowerShell Here"
"NoWorkingDirectory"=""
[HKEY_CLASSES_ROOT\Directory\Background\shell\powershellmenu\command]
#="C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe -NoExit -Command Set-Location -LiteralPath '%V'"
;
; Add context menu entry to Windows Explorer drive icons
;
[HKEY_CLASSES_ROOT\Drive\shell\powershellmenu]
#="PowerShell Here"
"NoWorkingDirectory"=""
[HKEY_CLASSES_ROOT\Drive\shell\powershellmenu\command]
#="C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe -NoExit -Command Set-Location -LiteralPath '%V'"
to run PowerShell as an admin in any location of file explorer go to that folder and use the shortcut "alt + f + s + a" to open powershell as an admin in that specific folder location
You can run the below command on the Windows Explorer address bar to open powershell , and it will open the path to this directory.
powershell.exe -noexit -command "Write-Host "Hello World""
Related
There are plenty of questions here which asks how to elevate priviliges from powershell, and almost all of them recommend this command:
Start-Process -Verb RunAs powershell.exe .....
(or pwsh.exe for Powershell Core)
And this works, it opens up a new Powershell window with elevated privileges, after having gone through a UAC block to verify access.
However, while I'm using Powershell, I'm doing it inside Windows Terminal, the new terminal application for Windows 10, and I would like to open a new instance of Windows Terminal with elevated privileges, not just a Powershell window.
So I tried these commands:
Start-Process -Verb RunAs wt
Start-Process -Verb RunAs wt.exe
Start-Process -Verb RunAs (Get-Command wt)
Start-Process -Verb RunAs "C:\Users\lasse\AppData\Local\Microsoft\WindowsApps\wt.exe"
They all fail with:
Start-Process: This command cannot be run due to the error: The file cannot be accessed by the system..
I'm assuming this has something to do with where the executable is located, within my profile, but if I right-click the Windows Terminal icon I have on my task bar and choose to run it as administrator, it opens up just fine. This is what I want to duplicate.
So is there a way for me to modify either the commands I tried above, or change some access setting that would make this work?
For my specific instance, I simply want to make it simpler to pop open an admin terminal, I don't need a way to elevate arbitrary commands, then I will happily use the commands I have already shown here.
Currently you cannot open an elevated wt.exe session from the command line without workarounds. Workarounds include using gsudo, Using Task Scheduler (I tested this one and it works but you need to use the full path to wt.exe and you can skip the shortcut creation step) OR if you are ok with a keyboard shortcut, the simplest way; using a keyboard shortcut to run Windows Terminal as Admin from the taskbar.
For your use case:
For my specific instance, I simply want to make it simpler to pop open
an admin terminal, I don't need a way to elevate arbitrary commands,
then I will happily use the commands I have already shown here.
The simplest approach will work:
Pin Windows Terminal as the first item on the task bar. Then hit Win+Ctrl+Shift+1 to open it as admin.
If you really must launch Windows Terminal from the command line from within Windows Terminal then create a task in the Task Scheduler:
Give the task a name, check 'Run with highest privileges'.
Choose the 'Actions' tab, click 'New', select 'Start a program' as the action. Put the full path to wt.exe in the 'Program/script field'. Click OK. Click OK again.
Click 'Conditions' tab, uncheck "Start the task only if the computer is on AC power".
Click 'Settings' tab, make sure "Allow task to be run on demand" is checked and uncheck "Stop the task if running for longer than".
Finally in your shell (Powershell), launch an elevated Windows Terminal session by running the command: schtasks /run /TN "TASK_NAME" where TASK_NAME is the name you gave the task in step 1.
Try this:
powershell "Start-Process -Verb RunAs cmd.exe '/c start wt.exe'"
Also check out these links:
WT.exe command line arguments:
https://learn.microsoft.com/en-us/windows/terminal/command-line-arguments?tabs=windows
Article about adding Open Windows Terminal Command Prompt to the context menu in Explorer (includes Admin):
https://dkcool.tailnet.net/2020/07/add-open-windows-terminal-command-prompt-to-the-explorer-context-menu-in-windows-10/
Article about adding Open Admin Command Prompt to the context menu in Explorer:
https://dkcool.tailnet.net/2019/05/add-open-admin-command-prompt-to-the-explorer-context-menu-in-windows-10/
Not a direct answer but another option if you have PowerToys is to:
Alt + Space, type Terminal,
Select Run as Administrator (or Ctrl + Shift + Enter)
You can install PowerToys using WinGet
With recent releases, this issue appears to be fixed. It works now, doing exactly as you originally tried and failed (Start-Process -verb RunAs wt). I would recommend trying again now with the latest releases (at least Windows Terminal, and perhaps PowerShell as well).
No need for workarounds anymore!!
Windows Terminal has a feature to automatically run as administrator in the preview; no need for workarounds now.
Pin to the Taskbar and hold Ctrl + Shift while left clicking on the Windows Terminal icon.
In my particular case I also need Windows Terminal opened as administrator all the time. This is what I did, run "where wt" to display the path where Windows Terminal application exe is located, it should be C:\Users\YOURUSER\AppData\Local\Microsoft\WindowsApps\wt.exe.
I created a shortcut to that file and checked "Run as administrator" in the advanced properties, then I just pinned it to start and voila. You can delete your temporary shortcut after that if you want.
You can create a shortcut to always run Windows Terminal as administrator using this powershell script:
$WshShell = New-Object -comObject WScript.Shell
$Shortcut = $WshShell.CreateShortcut("$Home\Desktop\Windows Terminal.lnk")
$Shortcut.TargetPath = "$env:LOCALAPPDATA\Microsoft\WindowsApps\Microsoft.WindowsTerminal_8wekyb3d8bbwe\wt.exe"
$Shortcut.Save()
$bytes = [System.IO.File]::ReadAllBytes("$Home\Desktop\Windows Terminal.lnk")
$bytes[0x15] = $bytes[0x15] -bor 0x20 #set byte 21 (0x15) bit 6 (0x20) ON
[System.IO.File]::WriteAllBytes("$Home\Desktop\Windows Terminal.lnk", $bytes)
You can just paste it and run it from Windows Powershell ISE, it will create a Windows Terminal.lnk file on your desktop. Whenever you double click on that shortcut Windows terminal will run as an admnnistrator
I know this answer does not fully match your question but given that also other answers were oriented in this way I hope this won't disturb the discussion.
I always need to run PowerShell as Administrator and I only want to use Windows Terminal, which given it's restrictions cannot be configured to run always as Administrator.
I hated the need to use shortcuts and other hacks I found being suggested online, so I think I found a better solution but you have to pay the cost of a 1/2 seconds at startup.
Locate your user profile (A profile is a Windows PowerShell ISE script that runs automatically when you start a new session) using _ $PROFILE
Edit profile with any preferred editor _ code $PROFILE
Adde the following code to the profile file and save it
if (-NOT ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) {
$host.ui.rawui.windowtitle="Bootstrapper"
Start-Process -Verb RunAs wt
} else {
$Processes = Get-Process | Where-Object {$_.mainWindowTitle -eq 'Bootstrapper' -and $_.name -eq 'WindowsTerminal'}
if($Processes.count -gt 0)
{
Stop-Process -Id $Processes[0].id
}
}
What the script do?
You can pin Windows Terminal icon to your application bar and when you click there WT will start as non elevated user, but the profile will understand if this is the case.
When you are not running as Administrator it will change the name of the window and start a new WT as administrator.
The new instance will also execute the profile file and if the instance is runinng as Administrator, it will look for the WT named Bootstrapper and kill it.
This proces takes between one and two seconds, I prefer this way other than right clicking on the icon.
It's likely you were just facing a Path issue. I know that the command examples you gave (e.g. Start-Process -verb RunAs wt) have worked for me for some time (as mentioned in #fialdrexs's answer).
Did you install Windows Terminal from a Github release or from the Store?
I currently have the following entry in my settings.json profiles list to add an elevated Windows Terminal to the drop down options:
{
// https://github.com/microsoft/terminal/issues/632#issuecomment-663686412
"name": "Windows Terminal (elevated)",
"commandline": "%SystemRoot%\\System32\\WindowsPowerShell\\v1.0\\powershell.exe -Command Start-Process -Verb RunAs \"shell:appsFolder\\Microsoft.WindowsTerminal_8wekyb3d8bbwe!App\"",
"hidden": false,
"icon": "ms-appx:///Images/Square44x44Logo.targetsize-32.png"
}
The comment with the GitHub link should get you to where I originally found this information.
I find a away to workaround, just create a file bat with content
powershell Start-Process -Verb RunAs wt.exe
Save file yourfile.bat to folder you want.
Add path folder to System Environment.
Press WINDOW + R and type file bat name.
Currently this problem was fixed, but it ended up with a weird issue. Running wt.exe from Win+R, searching it on start menu, and starting itself from the terminal, show the same error message.
The application was unable to start correctly (0xc0000022). Click OK
to close the application.
However it works when executing wt via Command Prompt, PowerShell, and PowerShell Core.
So just a quick workaround answer, start PowerShell and run the command,
Start-Process -Verb RunAs wt.exe;
or the simpler
start -verb runas wt
It seems that the only time Windows shows "Run with PowerShell" in the content menu of a ps1 file is when the default application is Notepad. If I change the default application to the PowerShell ISE (or any other editor, for that matter), the "Run with PowerShell" context item doesn't appear.
Windows 7 Professional SP1, WMF 4.0
In Windows 10 press Start then type "default app settings", click on "Default app settings". A new windows comes up "Choose default apps by file type". Scroll to ".ps1". Click on the current app icon, then select Notepad.
As elmonty stated, this will restore the "Run with PowerShell" context menu entry when right clicking on a ps1 file.
You can copy the below into a text file and import into your registry. This will open the PowerShell console and execute the script when you double click on a ps1 file.
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\Microsoft.PowerShellScript.1\Shell\Open\Command]
#="\"C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe\" \"-Command\" \"if((Get-ExecutionPolicy ) -ne 'AllSigned') { Set-ExecutionPolicy -Scope Process Bypass }; & '%1'\""
or open regedit, navigate to:
[HKEY_CLASSES_ROOT\Microsoft.PowerShellScript.1\Shell\Open\Command]
doulbe click on the (Default) string entry and enter the following in the "Value data:":
"C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" "-Command" "if((Get-ExecutionPolicy ) -ne 'AllSigned') { Set-ExecutionPolicy -Scope Process Bypass }; & '%1'"
I found out the answer. You must set the default application back to Notepad. This will restore the "Run with PowerShell" context item. Next, you have to edit the "Open with" application directly in the registry, here:
\HKEY_CLASSES_ROOT\Microsoft.PowerShellScript.1\Shell\Open\Command
Change the value to:
"C:\Windows\System32\WindowsPowerShell\v1.0\powershell_ise.exe" "%1"
Or you can change it to the editor of your choice.
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.
Sorry if this has been asked before, I've been looking around and it's hard to find what I want.
I know how to add a context menu item to a folder like so:
[HKEY_CLASSES_ROOT\Folder\shell\console2]
#="Open Console2 Here"
[HKEY_CLASSES_ROOT\Folder\shell\console2\command]
#="C:\\Program Files\\Console\\console.exe -d \"\"%1\"\""
but, that only works for right clicking on a folder. I want it so that you can be inside the folder, and click a blank part of that folder and get the context menu item as well. I also tried HKEY_CLASSES_ROOT\Directory\shell as well, but it does the same.
I figured out the answer. The folder is actually Directory\Background, you have to add the empty string value of NoWorkingDirectory into it, and the %1 in the command becomes a %V
[HKEY_CLASSES_ROOT\Directory\Background\shell\console2]
#="Open Console2 Here"
"NoWorkingDirectory"=""
[HKEY_CLASSES_ROOT\Directory\Background\shell\console2\command]
#="C:\\Program Files\\Console\\console.exe -d \"\"%V\"\""
Source:
saviert's comment at http://www.howtogeek.com/howto/windows-vista/make-command-prompt-here-always-display-for-folders-in-windows-vista#comment-57856
Console2 rocks. I added an 'Cmd here (Console2)' item to my explorer context menu.
Save the text below in a file named open-console2.reg then open it to import it to the Windows registry.
[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Directory\Background\shell\console2]
#="Cmd here (Console2)"
"NoWorkingDirectory"=""
[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Directory\Background\shell\console2\command]
#="\"C:\\Program Files (x86)\\Console2\\Console.exe\" -d \"%V\"\\"
Bonus 'bash here' item (assumes you have a Console2 tab named 'bash').
[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Directory\Background\shell\console2_bash]
#="Bash here (Console2)"
"NoWorkingDirectory"=""
[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Directory\Background\shell\console2_bash\command]
#="\"C:\\Program Files (x86)\\Console2\\Console.exe\" -t Bash -d \"%V\"\\"
I think the relevant part of the TortoiseSVN installer is here. Perhaps you can figure out all the necessary registry keys from that.
None of the above worked for me.
But this does (tested on Windows 7 Pro x64):
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\Folder\shell\Open console here\command]
#="u:\\users\\dave\\data\\bin\\Console2\\Console.exe cmd -r \"/k pushd %L\""
Replace the path with the path to your copy of console.exe (of course).
#Ben Voigt mentioned TortoiseSVN, you can also see WinMerge shell extension source code, or at last: create your own extension from scratch; I wanted to do something like this for XP but I have lots of other stuff to do now.
As a workaround, you can just open a folder in XP, and then select View->Explorer Bar->Folders, to have folder tree on left, and then you're able to right-click the folder (active folder gets hightlighted automatically).
Here it is if you prefer MinGW.
#!/bin/sh
reg add 'HKCR\Directory\Background\shell\sh' -d 'Open Bash window here'
reg add 'HKCR\Directory\Background\shell\sh\command' \
-d 'C:\MinGW\msys\1.0\bin\sh.exe -l'
printf 'cd -' >> ~/.profile
superuser.com/a/387273
According to my personal experience of Windows XP (SP3), you can open Console2 inside the current directory with a context menu entry using the following .reg file:
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\Folder\shell\console2]
#="Console2 Here"
[HKEY_CLASSES_ROOT\Folder\shell\console2\command]
#="C:\Program Files\Console\console.exe -d \"%1\""
If you look at the key value inside regedit.exe , you should see:
C:\Program Files\Console\console.exe -d "%1"
instead of:
C:\Program Files\Console\console.exe -d ""%1""
The latter would open Console2 in its default start directory.
This can be achieved in XP as well.
First open the program Run with the Windows key + R,
and type Regedit in the textbox.
Press Enter.
In the Registry open the Key : HKEY_CLASSES_ROOT
and then : *
You will now see a key called : shell
Rightclick on shell and point to New.
Click in de menu on Key.
Now type a name of your choice which you want to appear in the Rightclick menu.
Rightclick on the name you chose, again point to New and click Key.
Now type : command
Click on command and in the right pane of the Registry doubleclick on (Default).
In the textbox Value Data, type the path to an application you want to open via the chosen name in the rightclick menu.
For example : "C:\Program Files\CCleaner\CCleaner.exe"
Then type after the path : %1,
and leave a space between the end of the path and %1
It should look like this :
"C:\Program Files\CCleaner\CCleaner.exe" %1
This way, it's possible to open any kind of application you want.
There's only one drawback,
you have to rightclick another file to see the chosen name with which you can open the application.
When you rightclick a folder this will not work.
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.