Skip to content

Instantly share code, notes, and snippets.

@arieljannai
Created January 8, 2017 11:07
Show Gist options
  • Star 21 You must be signed in to star a gist
  • Fork 6 You must be signed in to fork a gist
  • Save arieljannai/1ba3be6462428d98c1e1ac8e5d702adb to your computer and use it in GitHub Desktop.
Save arieljannai/1ba3be6462428d98c1e1ac8e5d702adb to your computer and use it in GitHub Desktop.
Add PyCharm to context menu (right click menu)
@echo off
@rem throw this file in jetbrains installation folder, it takes the last created PyCharm folder (the latest ide update) for the script
FOR /F "delims=" %%i IN ('dir /b /ad-h /t:c /od -filter "PyCharm*"') DO SET a=%%i
SET PyCharmPath=C:\Program Files (x86)\JetBrains\%a%\bin\PyCharm64.exe
echo %PyCharmPath%
echo Adding file entries
@reg add "HKEY_CLASSES_ROOT\*\shell\Open in PyCharm" /t REG_SZ /v "" /d "Open in &PyCharm" /f
@reg add "HKEY_CLASSES_ROOT\*\shell\Open in PyCharm" /t REG_EXPAND_SZ /v "Icon" /d "%PyCharmPath%,0" /f
@reg add "HKEY_CLASSES_ROOT\*\shell\Open in PyCharm\command" /t REG_SZ /v "" /d "%PyCharmPath% \"%%1\"" /f
echo Adding folder entries
@reg add "HKEY_CLASSES_ROOT\Directory\shell\Open directory in PyCharm" /t REG_SZ /v "" /d "Open directory in &PyCharm" /f
@reg add "HKEY_CLASSES_ROOT\Directory\shell\Open directory in PyCharm" /t REG_EXPAND_SZ /v "Icon" /d "%PyCharmPath%,0" /f
@reg add "HKEY_CLASSES_ROOT\Directory\shell\Open directory in PyCharm\command" /t REG_SZ /v "" /d "%PyCharmPath% \"%%1\"" /f
echo Adding folder background entries
@reg add "HKEY_CLASSES_ROOT\Directory\background\shell\Open directory in PyCharm" /t REG_SZ /v "" /d "Open directory in &PyCharm" /f
@reg add "HKEY_CLASSES_ROOT\Directory\background\shell\Open directory in PyCharm" /t REG_EXPAND_SZ /v "Icon" /d "%PyCharmPath%,0" /f
@reg add "HKEY_CLASSES_ROOT\Directory\background\shell\Open directory in PyCharm\command" /t REG_SZ /v "" /d "%PyCharmPath% \"%%V\"" /f
pause
@mo-han
Copy link

mo-han commented Mar 16, 2020

Modified to better locate the pycharm bin path:

@echo off
setlocal

pushd "%~dp0"
set bin_dir=%cd%
if exist "%bin_dir%"\pycharm64.exe (
set bin=%bin_dir%\pycharm64.exe
goto :editreg
)
if exist "%bin_dir%"\pycharm.exe (
set bin=%bin_dir%\pycharm.exe
goto :editreg
)
if not defined %bin% (
echo Can not find pycharm*.exe
pause
goto :eof
)

:editreg
echo File
@reg add "HKEY_CLASSES_ROOT\*\shell\Open in PyCharm" /t REG_SZ /v "" /d "Open in PyCharm (&Y)"   /f
@reg add "HKEY_CLASSES_ROOT\*\shell\Open in PyCharm" /t REG_EXPAND_SZ /v "Icon" /d "%bin%,0" /f
@reg add "HKEY_CLASSES_ROOT\*\shell\Open in PyCharm\command" /t REG_SZ /v "" /d "%bin% \"%%1\"" /f
echo Folder
@reg add "HKEY_CLASSES_ROOT\Directory\shell\Open directory in PyCharm" /t REG_SZ /v "" /d "Open with PyCharm (&Y)"   /f
@reg add "HKEY_CLASSES_ROOT\Directory\shell\Open directory in PyCharm" /t REG_EXPAND_SZ /v "Icon" /d "%bin%,0" /f
@reg add "HKEY_CLASSES_ROOT\Directory\shell\Open directory in PyCharm\command" /t REG_SZ /v "" /d "%bin% \"%%1\"" /f
echo Folder background
@reg add "HKEY_CLASSES_ROOT\Directory\background\shell\Open directory in PyCharm" /t REG_SZ /v "" /d "Open with PyCharm (&Y)"   /f
@reg add "HKEY_CLASSES_ROOT\Directory\background\shell\Open directory in PyCharm" /t REG_EXPAND_SZ /v "Icon" /d "%bin%,0" /f
@reg add "HKEY_CLASSES_ROOT\Directory\background\shell\Open directory in PyCharm\command" /t REG_SZ /v "" /d "%bin% \"%%V\"" /f

pause

@gerroon
Copy link

gerroon commented Jul 20, 2020

Hi

None of these work now I have a dysfunctional entry in the context menu. How can I remove this or make it work?

@arieljannai
Copy link
Author

arieljannai commented Jul 21, 2020

@gerroon
To remove them - either manually from your registry editor, or by running reg delete KEY on the relevant entries.
To make it work - no idea at the moment, since I haven't used PyCharm plenty of time.

@Maxim-M-25
Copy link

Maxim-M-25 commented Oct 25, 2021

Hi, thanks for the script, everything work fine for me, only I changed the path to pycharm and it's fine (I didn't notice that there is a corrected version of this script, and copied the main code, only then I noticed that there is a modification for this script) :)

@tsjensen
Copy link

tsjensen commented Dec 8, 2021

In the third paragraph, it should be if not defined "%bin%" ( (with quotes) in order to support paths with spaces in them such as Program Files.

But otherwise works great - thanks a lot! 👍

@dnl-blkv
Copy link

dnl-blkv commented Sep 15, 2023

Neither of the options or fixes provided here worked for me unfortunately. Here's however, a fixed version that did work for me:

@echo off
setlocal enabledelayedexpansion

pushd "%~dp0"
set "bin_dir=%cd%"
if exist "!bin_dir!\pycharm64.exe" (
  set "bin=!bin_dir!\pycharm64.exe"
  goto :editreg
)
if exist "!bin_dir!\pycharm.exe" (
  set "bin=!bin_dir!\pycharm.exe"
  goto :editreg
)
if not defined bin (
  echo Can not find pycharm*.exe
  pause
  goto :eof
)

:editreg
echo File
reg add "HKEY_CLASSES_ROOT\*\shell\Open in PyCharm" /t REG_SZ /v "" /d "Open in PyCharm"   /f
reg add "HKEY_CLASSES_ROOT\*\shell\Open in PyCharm" /t REG_EXPAND_SZ /v "Icon" /d "!bin!,0" /f
reg add "HKEY_CLASSES_ROOT\*\shell\Open in PyCharm\command" /t REG_SZ /v "" /d "!bin! \"%%1\"" /f

echo Folder
reg add "HKEY_CLASSES_ROOT\Directory\shell\Open directory in PyCharm" /t REG_SZ /v "" /d "Open with PyCharm"   /f
reg add "HKEY_CLASSES_ROOT\Directory\shell\Open directory in PyCharm" /t REG_EXPAND_SZ /v "Icon" /d "!bin!,0" /f
reg add "HKEY_CLASSES_ROOT\Directory\shell\Open directory in PyCharm\command" /t REG_SZ /v "" /d "!bin! \"%%1\"" /f

echo Folder background
reg add "HKEY_CLASSES_ROOT\Directory\background\shell\Open directory in PyCharm" /t REG_SZ /v "" /d "Open with PyCharm"   /f
reg add "HKEY_CLASSES_ROOT\Directory\background\shell\Open directory in PyCharm" /t REG_EXPAND_SZ /v "Icon" /d "!bin!,0" /f
reg add "HKEY_CLASSES_ROOT\Directory\background\shell\Open directory in PyCharm\command" /t REG_SZ /v "" /d "!bin! \"%%V\"" /f

pause

@caVenikk
Copy link

How do I make this work in the Windows 11 quick menu?

@yousefpahang
Copy link

@echo off
SET PYCHARM_PATH=C:\Program Files (x86)\JetBrains\PyCharm 2023.2\bin\pycharm64.exe
SET ICON_PATH=%PYCHARM_PATH%,0

reg add "HKEY_CLASSES_ROOT*\shell\Open with PyCharm" /ve /d "Open with PyCharm" /f
reg add "HKEY_CLASSES_ROOT*\shell\Open with PyCharm" /v "Icon" /d "%ICON_PATH%" /f
reg add "HKEY_CLASSES_ROOT*\shell\Open with PyCharm\command" /ve /d ""%PYCHARM_PATH%" "%%1"" /f

reg add "HKEY_CLASSES_ROOT\Directory\shell\Open with PyCharm" /ve /d "Open with PyCharm" /f
reg add "HKEY_CLASSES_ROOT\Directory\shell\Open with PyCharm" /v "Icon" /d "%ICON_PATH%" /f
reg add "HKEY_CLASSES_ROOT\Directory\shell\Open with PyCharm\command" /ve /d ""%PYCHARM_PATH%" "%%1"" /f

reg add "HKEY_CLASSES_ROOT\Directory\Background\shell\Open with PyCharm" /ve /d "Open with PyCharm" /f
reg add "HKEY_CLASSES_ROOT\Directory\Background\shell\Open with PyCharm" /v "Icon" /d "%ICON_PATH%" /f
reg add "HKEY_CLASSES_ROOT\Directory\Background\shell\Open with PyCharm\command" /ve /d ""%PYCHARM_PATH%" "%%V"" /f

echo PyCharm context menu option and icon added.
pause

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment