Add an Open Anaconda Prompt context menu item to folders in Windows

Ever wanted to open an Anaconda Prompt by right clicking the folder in Explorer in Windows 10? Git Bash has an entry in the right-click context menu and so does Powershell (just Shift + Right-Click). Anaconda doesn't have one by default and I wanted to add it. But none of the answers on Stack Overflow or a bunch of other sites worked. I finally got it working after reading the Wikipedia entry for cmd.exe.

Batch file

Here is the batch file:

REM Run this as administator. 
REM Check the path to the activate script depending where you installed Anaconda / version.

REG ADD HKCR\Directory\Background\shell\Anaconda\ /ve /f /d "Anaconda Prompt Here"
REG ADD HKCR\Directory\Background\shell\Anaconda\command /f /ve /t REG_EXPAND_SZ /d "cmd.exe /k pushd %%v && %%USERPROFILE%%\Anaconda3\Scripts\activate.bat"
REG ADD HKCR\Directory\shell\Anaconda\ /ve /f /d "Anaconda Prompt Here"
REG ADD HKCR\Directory\shell\Anaconda\command /f /ve /t REG_EXPAND_SZ /d "cmd.exe /k pushd %%v && %%USERPROFILE%%\Anaconda3\Scripts\activate.bat"

Save it as “anaconda.bat” and run it as Administrator and it will install the correct registry keys. After running this script, the prompt will be in your right-click context menu for each folder in Explorer.

I'll attempt to explain how this works:

  • There are separate entries for Directory\Background\shell and Directory\shell. I believe the Background entry is for right-clicking on the background / empty part of the folder in Explorer (right pane) and the plain Shell entry is for right-clicking the folder itself (in either the left or right panes).
  • Both entries call the same command
  • cmd.exe /k [command] runs the command specified. In this case, it is pushd %%v && %%USERPROFILE%%\Anaconda3\Scripts\activate.bat which is two commands put together.
    • The pushd %%v switches the prompt to the folder being clicked. There are two % because it is an escaped character in the batch file.
    • && strings two commands to be executed in sequence
    • %%USERPROFILE%%\Anaconda3\Scripts\activate.bat is the command to activate the Anaconda environment, if you installed it in your user folder. It will be stored in the registry as %USERPROFILE%\Anaconda3\Scripts\activate.bat, which means each user will use their own copy of activate.bat in their own folder.

About Peter Yu I am a research and development professional with expertise in the areas of image processing, remote sensing and computer vision. I received BASc and MASc degrees in Systems Design Engineering at the University of Waterloo. My working experience covers industries ranging from district energy to medical imaging to cinematic visual effects. I like to dabble in 3D artwork, I enjoy cycling recreationally and I am interested in sustainable technology. More about me...

Feel free to contact me with any questions about this site at [user]@[host] where [user]=web and [host]

Copyright © 1997 - 2021 Peter Yu