Is there a silent parameter to associate files without entering the interface using "Associate files with XnViewMP.exe"?
Moderators: XnTriq, helmut, xnview
-
- Posts: 4
- Joined: Sat Jul 25, 2020 2:36 am
Is there a silent parameter to associate files without entering the interface using "Associate files with XnViewMP.exe"?
When temporarily using XnViewMP, it is necessary to set file associations, and I hope there is a way to achieve file association without human intervention. Is it possible to run the command "Associate files with XnViewMP.exe" in the cmd environment with a certain parameter to achieve silent association?
-
- Author of XnView
- Posts: 45224
- Joined: Mon Oct 13, 2003 7:31 am
- Location: France
Re: Is there a silent parameter to associate files without entering the interface using "Associate files with XnViewMP.e
"Associate files with XnViewMP.exe" is only needed on Win7
Pierre.
-
- Posts: 4
- Joined: Sat Jul 25, 2020 2:36 am
-
- Moderator & Librarian
- Posts: 6402
- Joined: Sun Sep 25, 2005 3:00 am
- Location: Ref Desk
Re: Is there a silent parameter to associate files without entering the interface using "Associate files with XnViewMP.e
- SS64.com command line reference: assoc
“Display or change the association between a file extension and a fileType”
Related topics:https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/assoc wrote:This command is only supported within cmd.exe and is not available from PowerShell. Though you can use cmd /c assoc as a workaround.
-
- Posts: 4
- Joined: Sat Jul 25, 2020 2:36 am
Re: Is there a silent parameter to associate files without entering the interface using "Associate files with XnViewMP.e
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 thisXnTriq wrote: ↑Thu Aug 17, 2023 12:30 pm
- SS64.com command line reference: assoc
“Display or change the association between a file extension and a fileType”Related topics:https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/assoc wrote:This command is only supported within cmd.exe and is not available from PowerShell. Though you can use cmd /c assoc as a workaround.
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
-
- Moderator & Librarian
- Posts: 6402
- Joined: Sun Sep 25, 2005 3:00 am
- Location: Ref Desk
-
- Moderator & Librarian
- Posts: 6402
- Joined: Sun Sep 25, 2005 3:00 am
- Location: Ref Desk