Based on your guidance, I wrote a script, but it still cannot replace the default image viewer program in many cases. So I hope can find method is more suitable for the interface method than this
Code: Select all
@echo off
pushd "%~dp0"
setlocal enabledelayedexpansion
del tmp.reg >nul 2>nul
set p=%cd%
set soft_exe=xnviewmp.exe
set software=XnViewMP
:Copy configuration
md "%APPDATA%\%software%"
copy /y xnview.ini "%APPDATA%\%software%"
:Begin
for %%i in (raw,crw,cr2,raf,dcr,mrw,nef,orf,pef,srf,x3f,iff,sgi,xbm,xpm,emf,pcx,tga,png,bmp,jpg,jpeg,gif,ico,psd,tif,tiff,ais,ani,cur,emf,eps,lwf,webp,wmf,heic) do assoc .%%i=%software%.%%i&ftype %software%.%%i="%cd%\%soft_exe%" "%%1"
>XnViewMP.xml echo ^<?xml version="1.0" encoding="ANSI"?^>
>>XnViewMP.xml echo ^<DefaultAssociations^>
echo >tmp.reg Windows Registry Editor Version 5.00
for %%i in (raw,crw,cr2,raf,dcr,mrw,nef,orf,pef,srf,x3f,iff,sgi,xbm,xpm,emf,pcx,tga,png,bmp,jpg,jpeg,gif,ico,psd,tif,tiff,ais,ani,cur,emf,eps,lwf,webp,wmf,heic) do (
echo >>tmp.reg [-HKEY_CLASSES_ROOT\.%%i]
echo >>tmp.reg [HKEY_CLASSES_ROOT\.%%i]
echo >>tmp.reg @="%software%.%%i"
echo >>tmp.reg "PerceivedType"="%software%"
echo >>tmp.reg "Content Type"=""
echo >>tmp.reg [HKEY_CLASSES_ROOT\.%%i\OpenWithList]
echo >>tmp.reg [HKEY_CLASSES_ROOT\.%%i\OpenWithList\%soft_exe%]
echo >>tmp.reg @=""
echo >>tmp.reg [HKEY_CLASSES_ROOT\.%%i\OpenWithProgIds]
echo >>tmp.reg "%software%.%%i"=""
echo >>tmp.reg [HKEY_CLASSES_ROOT\.%%i\PersistentHandler]
echo >>tmp.reg @="{098f2470-bae0-11cd-b579-08002b30bfeb}"
echo >>tmp.reg [HKEY_CLASSES_ROOT\.%%i\UndoClass]
echo >>tmp.reg @="%software%.%%i"
echo >>tmp.reg [-HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.%%i]
echo >>tmp.reg [HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.%%i]
echo >>tmp.reg [HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.%%i\OpenWithProgids]
echo >>tmp.reg "%software%.%%i"=hex^(0^)^:
echo >>tmp.reg [HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.%%i\UserChoice]
echo >>tmp.reg "Hash"="AUGg6DegRxo="
echo >>tmp.reg "ProgId"="%software%.%%i"
>>XnViewMP.xml echo ^<Association Identifier=".%%i" ProgId="%software%.%%i" ApplicationName="%software%" /^>
)
echo. >>tmp.reg
>>XnViewMP.xml echo ^</DefaultAssociations^>
>>XnViewMP.xml echo.
regedit /s tmp.reg
dism /online /Import-DefaultAppAssociations:"XnViewMP.xml"
del tmp.reg
del XnViewMP.xml
:EXIT