Is there a silent parameter to associate files without entering the interface using "Associate files with XnViewMP.exe"?

Ask for help and post your question on how to use XnView MP.

Moderators: XnTriq, helmut, xnview

msold5
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"?

Post by msold5 »

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?
User avatar
xnview
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

Post by xnview »

"Associate files with XnViewMP.exe" is only needed on Win7
Pierre.
msold5
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

Post by msold5 »

xnview wrote: Thu Aug 17, 2023 7:19 am "Associate files with XnViewMP.exe" is only needed on Win7
Can "xnviewmp.exe" have command line arguments that allow for file association without displaying a user interface or at least not requiring confirmation for file association?
User avatar
XnTriq
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

Post by XnTriq »

  • SS64.com command line reference: assoc
    “Display or change the association between a file extension and a fileType”
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.
Related topics:
msold5
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

Post by msold5 »

XnTriq 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”
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.
Related topics:
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
User avatar
XnTriq
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

Post by XnTriq »

msold5 wrote: Fri Aug 18, 2023 9:47 amBased 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
Wow! Thanks for sharing :-D
User avatar
XnTriq
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

Post by XnTriq »