<critical_lessons>
<lesson name="registry_operations"> **NEVER use `reg.exe` for commands containing quotes** - quotes get stripped unpredictably.ALWAYS use PowerShell's native registry provider:
# Create key $path = "Registry::HKEY_CLASSES_ROOT\Directory\shell\MyEntry" $null = New-Item -Path $path -Force Set-ItemProperty -Path $path -Name "(Default)" -Value "My Menu Item" Set-ItemProperty -Path $path -Name "Icon" -Value "myapp.exe" # Create command subkey $null = New-Item -Path "$path\command" -Force Set-ItemProperty -Path "$path\command" -Name "(Default)" -Value 'myapp.exe "%1"'
Before writing new registry entries, ALWAYS examine existing working examples:
# List all context menu entries reg query "HKEY_CLASSES_ROOT\Directory\shell" # Show specific entry with command reg query "HKEY_CLASSES_ROOT\Directory\shell\<entry>\command" # Full recursive dump reg query "HKEY_CLASSES_ROOT\Directory\shell" /s
# GOOD - quotes preserved $cmd = 'wsl.exe --cd "%1"' # BAD - quotes may be stripped $cmd = "wsl.exe --cd `"%1`""
Always use -LiteralPath instead of -Path for paths with special characters:
Set-Location -LiteralPath $folderPath # Handles [brackets], spaces, etc.
- •
Create test folder:
D:\Test Folder With Spaces - •
Create test folder:
D:\Test[Brackets] - •
Test BOTH right-click scenarios:
- •Right-click ON the folder
- •Right-click INSIDE the folder (empty space)
- •
Verify registry entries after creation:
powershellreg query "HKEY_CLASSES_ROOT\Directory\shell\YourEntry\command"
Common WT commands:
wt.exe -d "path" # Open at directory (uses default profile) wt.exe -p "Profile Name" -d "path" # Specific profile wt.exe -p "Command Prompt" -d "path" cmd /k command # CMD with command
# PowerShell script with proper parameter handling param([string]$Path) & wt.exe -d $Path
If batch files are required, use %~1 to strip outer quotes:
@echo off wt.exe -d "%~1"
</critical_lessons>
<proven_patterns> These patterns are proven to work from registry entries:
cmd.exe /s /k pushd "%V" powershell.exe -NoExit -Command Set-Location -LiteralPath '%V' wsl.exe --cd "%V" wt.exe -d "%V" -p "Command Prompt" "C:\Program Files\App\app.exe" "%1"
</proven_patterns>
<debugging_checklist> When context menu entries don't work:
- • Check if
\commandsubkey exists:reg query "...\command" - • Verify quotes are preserved in the command value
- • Test with a simple path first (no spaces)
- • Test with a path containing spaces
- • Check Windows Event Viewer for errors
- • Try running the command manually in cmd/PowerShell </debugging_checklist>