Skip to content

Instantly share code, notes, and snippets.

@avengerx
Last active November 24, 2025 10:42
Show Gist options
  • Select an option

  • Save avengerx/0920adfef012cbc8d0b727fb44cc43f1 to your computer and use it in GitHub Desktop.

Select an option

Save avengerx/0920adfef012cbc8d0b727fb44cc43f1 to your computer and use it in GitHub Desktop.
Add context menu 'Edit with Paint.NET' for supported file extensions (system-wide or per-user)
@ECHO OFF
setlocal EnableDelayedExpansion
set uninstall=no
set classkey=HKEY_CLASSES_ROOT
if [%1]==[uninstall] set uninstall=yes
net session > nul 2>&1
if %ERRORLEVEL% NEQ 0 (
echo Setting up for current user ^(run as Administrator for system-wide change^).
set classkey=HKEY_CURRENT_USER\Software\Classes
) else (
echo Setting up for all users ^(run as unprivileged user for current user only^).
)
for /F tokens^=2* %%G in (
'reg query HKEY_LOCAL_MACHINE\SOFTWARE\paint.net /v TARGETDIR ^| findstr /rc:" REG_SZ "'
) do set pdnpath=%%H
if ["%pdnpath%"]==[] (
echo "Paint.NET installation registry keys not found. Unable to probe installation path."
goto error
)
set pdnexec=%pdnpath%\PaintDotNet.exe
echo PDN Path: %pdnpath%
if [%uninstall%]==[yes] (
echo ck=%classkey%
reg query %classkey%\*\Shell\OpenPDN /ve > nul 2>&1
if !ERRORLEVEL! EQU 0 (
reg delete %classkey%\*\Shell\OpenPDN /f > nul 2>&1
if !ERRORLEVEL! EQU 0 (
echo Removed shell extension.
) else (
echo Failed to remove shell extension.
)
) else (
echo Shell extension not installed at all.
)
goto end
)
set addexts=
for /F Tokens^=1 %%G in (
'reg query HKEY_LOCAL_MACHINE\SOFTWARE\paint.net\Capabilities\FileAssociations ^| findstr /rc:" REG_SZ "'
) do (
for /F "tokens=2*" %%H in (
'reg query %classkey%\%%G /ve 2^> nul ^| findstr /rc:" REG_SZ " ^|^| reg query HKEY_CLASSES_ROOT\%%G /ve 2^> nul ^| findstr /rc:" REG_SZ " ^|^| echo x x nothing'
) do (
if [%%I]==[paint.net.1] (
echo %%G opens with Paint.NET by default -- no shell extension needed.
) else (
reg query %classkey%\*\Shell\OpenPDN /ve > nul 2>&1
if !ERRORLEVEL! EQU 0 (
echo Shell extensions already set for %%G.
) else (
set "addexts=!addexts! OR System.FileName:\"*%%G\""
echo Should add shell extension for %%G.
)
)
)
)
if not ["%addexts%"]==[""] (
reg add %classkey%\*\Shell\OpenPDN /f /ve /t REG_SZ /d "Edit with &Paint.NET" > nul
reg add %classkey%\*\Shell\OpenPDN /f /v Icon /t REG_SZ /d "\"%pdnexec%\",0" > nul
reg add %classkey%\*\Shell\OpenPDN /f /v AppliesTo /t REG_SZ /d "%addexts:~4%" > nul
reg add %classkey%\*\Shell\OpenPDN\command /f /ve /t REG_SZ /d "\"%pdnexec%\" \"%%1\"" > nul
echo Created shell extension for Paint.NET with supported file extensions.
) else (
echo Couldn't find extension to associate to Paint.NET.
goto error
)
goto end
:error
exit /b 1
goto end
:end
@aLanaMaunz
Copy link
Copy Markdown

not working if the path contains a whitespace.
change line 19 to: if ["%pdnpath%"]==[] (

@avengerx
Copy link
Copy Markdown
Author

In fact, I have my local copy installed in a path without spaces, thanks for the heads up!

@VorpalVulpes
Copy link
Copy Markdown

dude this is amazing thank you so much

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