NeuroAgent

Add EmbyIgnore Option to Windows Context Menu

Learn how to create a Windows context menu item that generates .embyignore files with folder-specific content. Complete guide with PowerShell scripts and registry setup.

Question

How to create a Windows context menu item that generates a .embyignore file with folder-specific content?

I need to create a context menu item in Windows Explorer that:

  • Adds an option called “Create EmbyIgnore File” when right-clicking on a folder
  • Creates a text file named “.embyignore” inside the selected folder
  • Populates the file with “folder name/*” where “folder name” is the name of the folder being right-clicked

I’m familiar with creating Windows registry keys but need guidance on the specific code to dynamically insert the folder name into the file content.

NeuroAgent

To create a Windows context menu item that generates a .embyignore file with folder-specific content, you’ll need to combine registry editing with a PowerShell script that dynamically inserts the folder name. This involves creating a registry entry that points to a PowerShell script, which will then generate the .embyignore file with the appropriate “folder name/*” content.


Contents


Registry Key Setup

First, you need to create the registry structure that will add your context menu option. Open Registry Editor by pressing Win + R, typing regedit, and hitting Enter.

  1. Navigate to: HKEY_CLASSES_ROOT\Directory\background\shell
  2. Right-click on shell → New → Key
  3. Name the key CreateEmbyIgnore (or your preferred name)
  4. Right-click on your new key → New → String Value
  5. Name it Icon (optional - for custom icon)
  6. Double-click Icon and set value to: C:\Windows\System32\shell32.dll,3 (or your preferred icon)

Now right-click on your CreateEmbyIgnore key → New → String Value → Name it Position and set it to Top to appear at the top of the context menu.


PowerShell Script Creation

Create a PowerShell script file that will generate the .embyignore file with dynamic content. Save this script as CreateEmbyIgnore.ps1 in a location like C:\Scripts\CreateEmbyIgnore.ps1:

powershell
param(
    [Parameter(Mandatory=$true)]
    [string]$FolderPath
)

# Get the folder name from the path
$folderName = Split-Path -Path $FolderPath -Leaf

# Define the content for the .embyignore file
$content = "$folderName/*"

# Define the full path for the .embyignore file
$ignoreFilePath = Join-Path -Path $FolderPath -ChildPath ".embyignore"

# Create the file with the dynamic content
$content | Out-File -FilePath $ignoreFilePath -Encoding UTF8

# Optional: Show success message
Write-Host "Created .embyignore file in: $ignoreFilePath"
Write-Host "Content: $content"

This script takes the folder path as a parameter, extracts the folder name, and creates the .embyignore file with the “folder name/*” content.


Registry Integration

Now create the registry entry that will execute your PowerShell script. Right-click on your CreateEmbyIgnore key → New → Key → Name it command.

Double-click on the (Default) value in the command key and set it to:

C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -ExecutionPolicy Bypass -File "C:\Scripts\CreateEmbyIgnore.ps1" -FolderPath "%V"

Important: Replace C:\Scripts\CreateEmbyIgnore.ps1 with the actual path to your script file. The %V variable represents the folder path when you right-click on a folder background.

For folder-specific context menus (when right-clicking on the folder itself rather than background), you might use %1 instead of %V.


Testing and Troubleshooting

To test your implementation:

  1. Right-click on any folder background
  2. You should see “Create EmbyIgnore File” in the context menu
  3. Click it and check if the .embyignore file is created

Common issues and solutions:

  • Script not executing: Check execution policy by running Get-ExecutionPolicy in PowerShell. If it’s Restricted, run Set-ExecutionPolicy RemoteSigned in an elevated PowerShell window.
  • Folder name not appearing: Ensure you’re using the correct variable (%V for background, %1 for folder).
  • File not created: Verify the script path in the registry and ensure you have write permissions to the target folder.
  • Special characters: If folder names contain special characters, you may need to add additional escaping in your PowerShell script.

Here’s an enhanced version of the script that handles special characters:

powershell
param(
    [Parameter(Mandatory=$true)]
    [string]$FolderPath
)

try {
    # Get the folder name from the path
    $folderName = Split-Path -Path $FolderPath -Leaf
    
    # Handle special characters by escaping them for the ignore file pattern
    $escapedFolderName = $folderName -replace '([[\]{}()*+?.\\^$|])', '`$1'
    
    # Define the content for the .embyignore file
    $content = "$escapedFolderName/*"
    
    # Define the full path for the .embyignore file
    $ignoreFilePath = Join-Path -Path $FolderPath -ChildPath ".embyignore"
    
    # Create the file with the dynamic content
    $content | Out-File -FilePath $ignoreFilePath -Encoding UTF8
    
    # Show success message
    Write-Host "Successfully created .embyignore file in: $ignoreFilePath"
    Write-Host "Content: $content"
}
catch {
    Write-Host "Error creating .embyignore file: $_" -ForegroundColor Red
    exit 1
}

Alternative Methods

Using Batch Script Instead of PowerShell

If you prefer a batch file approach, create CreateEmbyIgnore.bat:

batch
@echo off
set "folderpath=%~1"
for %%F in ("%folderpath%") do set "foldername=%%~nxF"
echo %foldername%/* > "%folderpath%\.embyignore"
echo Created .embyignore file in: %folderpath%

Registry entry would be:

"%~dp0CreateEmbyIgnore.bat" "%V"

Using Registry File (.reg) for Easy Deployment

For easier deployment, create a .reg file that users can double-click:

reg
Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\Directory\background\shell\CreateEmbyIgnore]
@="Create EmbyIgnore File"
"Icon"="C:\\Windows\\System32\\shell32.dll,3"
"Position"="Top"

[HKEY_CLASSES_ROOT\Directory\background\shell\CreateEmbyIgnore\command]
@="C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe -ExecutionPolicy Bypass -File \"C:\\Scripts\\CreateEmbyIgnore.ps1\" -FolderPath \"%V\""

Save this as AddEmbyIgnoreContextMenu.reg and users can simply double-click it to install the context menu.


Sources

  1. How add context menu item to Windows Explorer for folders - Stack Overflow
  2. Add PowerShell file (*.ps1) to New Context Menu of File Explorer - WinAero
  3. How to Add Custom Shortcuts to the Windows 11 or 10 Context Menu - Tom’s Hardware
  4. Adding right-click context menu items in Windows 10 - Klein Embedded
  5. Adding PowerShell command to right click menu both on and in a folder - Super User

Conclusion

Creating a Windows context menu item that generates a .embyignore file with dynamic folder-specific content is straightforward once you understand the registry-PowerShell integration. The key steps involve:

  1. Setting up the registry structure under HKEY_CLASSES_ROOT\Directory\background\shell
  2. Creating a PowerShell script that extracts the folder name and generates the appropriate content
  3. Integrating the script execution through the registry command key
  4. Testing and handling edge cases like special characters

This approach provides a seamless way to automate the creation of .embyignore files for Emby media server configuration, saving you time and ensuring consistency across your media library structure. For deployment across multiple systems, consider using the .reg file method for easy installation and removal.