Skip to content

Instantly share code, notes, and snippets.

@zanysoft
Created June 5, 2023 08:53
Show Gist options
  • Save zanysoft/66b4fd4998d4a2845ceb63f09838dfbc to your computer and use it in GitHub Desktop.
Save zanysoft/66b4fd4998d4a2845ceb63f09838dfbc to your computer and use it in GitHub Desktop.
Add Open Folder in PHPStorm to Windows Context Menu
@ECHO off
setlocal EnableDelayedExpansion
SET PhpStormPath="C:\Program Files\JetBrains\PhpStorm 2021.3\bin\phpstorm64.exe"
IF EXIST %PhpStormPath% (ECHO File found: %PhpStormPath%) ELSE (ECHO File not found: %PhpStormPath% && CALL :LoadExeFile PhpStormPath)
SET updated=false
IF EXIST %PhpStormPath% (
reg QUERY "HKEY_CLASSES_ROOT\*\shell\PhpStorm" > nul 2> nul
if %errorlevel% GTR 0 (
echo Adding file entries
@reg add "HKEY_CLASSES_ROOT\*\shell\PhpStorm" /t REG_SZ /v "" /d "Open in PhpStorm" /f
@reg add "HKEY_CLASSES_ROOT\*\shell\PhpStorm" /t REG_EXPAND_SZ /v "Icon" /d "%PhpStormPath%,0" /f
@reg add "HKEY_CLASSES_ROOT\*\shell\PhpStorm\command" /t REG_SZ /v "" /d "%PhpStormPath% \"%%1\"" /f
SET updated=true
)
reg QUERY "HKEY_CLASSES_ROOT\Directory\Background\shell\PhpStorm" > nul 2> nul
if %errorlevel% GTR 0 (
echo Adding within a folder entries
@reg add "HKEY_CLASSES_ROOT\Directory\Background\shell\PhpStorm" /t REG_SZ /v "" /d "Open with PhpStorm" /f
@reg add "HKEY_CLASSES_ROOT\Directory\Background\shell\PhpStorm" /t REG_EXPAND_SZ /v "Icon" /d "%PhpStormPath%,0" /f
@reg add "HKEY_CLASSES_ROOT\Directory\Background\shell\PhpStorm\command" /t REG_SZ /v "" /d "%PhpStormPath% \"%%V\"" /f
SET updated=true
)
reg QUERY "HKEY_CLASSES_ROOT\Directory\shell\PhpStorm" > nul 2> nul
if %errorlevel% GTR 0 (
echo Adding folder entries
@reg add "HKEY_CLASSES_ROOT\Directory\shell\PhpStorm" /t REG_SZ /v "" /d "Open with PhpStorm" /f
@reg add "HKEY_CLASSES_ROOT\Directory\shell\PhpStorm" /t REG_EXPAND_SZ /v "Icon" /d "%PhpStormPath%,0" /f
@reg add "HKEY_CLASSES_ROOT\Directory\shell\PhpStorm\command" /t REG_SZ /v "" /d "%PhpStormPath% \"%%1\"" /f
SET updated=true
)
if %updated% equ true ( ECHO Registry Updated Successfull! ) ELSE (ECHO Registry not updated may be values already exists!)
) ELSE ( echo File %PhpStormPath% does not exist )
endlocal
PAUSE
EXIT /B %ERRORLEVEL%
:LoadExeFile
SET ps_fn=ofd.ps1
ECHO [System.Reflection.Assembly]::LoadWithPartialName("System.windows.forms") ^| out-null > %ps_fn%
ECHO $OpenFileDialog = New-Object System.Windows.Forms.OpenFileDialog >> %ps_fn%
ECHO $OpenFileDialog.initialDirectory = "C:\Program Files\JetBrains" >> %ps_fn%
ECHO $OpenFileDialog.filter = "Exe File (*.exe)|*.exe" >> %ps_fn%
ECHO $OpenFileDialog.ShowDialog() >> %ps_fn%
ECHO $OpenFileDialog.filename >> %ps_fn%
for /F "tokens=* usebackq" %%a in (`powershell -executionpolicy bypass -file %ps_fn%`) do if not "%%a" == "Cancel" if not "%%a" == "OK" SET filename=%%a
del %ps_fn%
SET "%~1=%filename%"
EXIT /B 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment