How to associate Photo Viewer using ftype and assoc


  1. Posts : 7
    Windows 10
       #1

    How to associate Photo Viewer using ftype and assoc


    Hello.
    I want to associate png, bmp, jpg/jpeg with Windows Photo Viewer in Windows 10 (8.1) through console and without using GUI (Settings — Apps — Default apps — setting up Photo Viewer as a default app).
    Here is my code, but unfortunately it doesn't associate at all, but works with out any errors. Restarting Explorer or PC doesn't help.
    Code:
    IF (!(Test-Path Registry::HKEY_CLASSES_ROOT\Applications\photoviewer.dll\shell\open\command))
    {
        New-Item -Path Registry::HKEY_CLASSES_ROOT\Applications\photoviewer.dll\shell\open\command -Force
    }
    IF (!(Test-Path Registry::HKEY_CLASSES_ROOT\Applications\photoviewer.dll\shell\open\DropTarget))
    {
        New-Item -Path Registry::HKEY_CLASSES_ROOT\Applications\photoviewer.dll\shell\open\DropTarget -Force
    }
    IF (!(Test-Path Registry::HKEY_CLASSES_ROOT\Applications\photoviewer.dll\shell\print\command))
    {
        New-Item -Path Registry::HKEY_CLASSES_ROOT\Applications\photoviewer.dll\shell\print\command -Force
    }
    IF (!(Test-Path Registry::HKEY_CLASSES_ROOT\Applications\photoviewer.dll\shell\print\DropTarget))
    {
        New-Item -Path Registry::HKEY_CLASSES_ROOT\Applications\photoviewer.dll\shell\print\DropTarget -Force
    }
    New-ItemProperty -Path Registry::HKEY_CLASSES_ROOT\Applications\photoviewer.dll\shell\open -Name MuiVerb -Type String -Value "@photoviewer.dll,-3043" -Force
    New-ItemProperty -Path Registry::HKEY_CLASSES_ROOT\Applications\photoviewer.dll\shell\open\command -Name "(Default)" -Type ExpandString -Value "%SystemRoot%\System32\rundll32.exe `"%ProgramFiles%\Windows Photo Viewer\PhotoViewer.dll`", ImageView_Fullscreen %1" -Force
    New-ItemProperty -Path Registry::HKEY_CLASSES_ROOT\Applications\photoviewer.dll\shell\open\DropTarget -Name Clsid -Type String -Value "{FFE2A43C-56B9-4bf5-9A79-CC6D4285608A}" -Force
    New-ItemProperty -Path Registry::HKEY_CLASSES_ROOT\Applications\photoviewer.dll\shell\print\command -Name "(Default)" -Type ExpandString -Value "%SystemRoot%\System32\rundll32.exe `"%ProgramFiles%\Windows Photo Viewer\PhotoViewer.dll`", ImageView_Fullscreen %1" -Force
    New-ItemProperty -Path Registry::HKEY_CLASSES_ROOT\Applications\photoviewer.dll\shell\open\DropTarget -Name Clsid -Type String -Value "{60fd46de-f830-4894-a628-6fa81bc0190d}" -Force
    
    cmd.exe /c "assoc .bmp=Paint.Picture"
    cmd.exe /c "assoc .jpg=jpegfile"
    cmd.exe /c "assoc .jpeg=jpegfile"
    cmd.exe /c "assoc .png=pngfile"
    cmd.exe /c "assoc .tif=TIFImage.Document"
    cmd.exe /c "assoc .tiff=TIFImage.Document"
    
    cmd.exe /c 'ftype Paint.Picture=%windir%\System32\rundll32.exe "%ProgramFiles%\Windows Photo Viewer\PhotoViewer.dll", ImageView_Fullscreen %1'
    cmd.exe /c 'ftype jpegfile=%windir%\System32\rundll32.exe "%ProgramFiles%\Windows Photo Viewer\PhotoViewer.dll", ImageView_Fullscreen %1'
    cmd.exe /c 'ftype pngfile=%windir%\System32\rundll32.exe "%ProgramFiles%\Windows Photo Viewer\PhotoViewer.dll", ImageView_Fullscreen %1'
    cmd.exe /c 'ftype TIFImage.Document=%windir%\System32\rundll32.exe "%ProgramFiles%\Windows Photo Viewer\PhotoViewer.dll", ImageView_Fullscreen %1'
    Source: https://www.reddit.com/r/sysadmin/comments/72vv31/set_windows_photo_viewer_as_default_app_on/
    Source 2: Forcing Windows to use Windows Photo Viewer | NHL Data Blog
    How to really(!) associate an file extension to new program? - DosTips.com
    Last edited by farag; 01 Mar 2018 at 04:58.
      My Computer


  2. Posts : 42,991
    Win 10 Pro (22H2) (2nd PC is 22H2)
       #2

    Why not
    a. associate it
    b. export the relevant keys
    c. build a reg file that you can merge
    registry - Add reg file via Command Line on Windows CE device - Stack Overflow

    Just a thought..
      My Computers


  3. Posts : 7
    Windows 10
    Thread Starter
       #3

    dalchina said:
    Why not
    The main key for me is not to mark "Always use this app...". After excuting script I want to open jpg, bmp files instantly. Anyway, may be it's not possible, only through Settings.
      My Computer


  4. Posts : 42,991
    Win 10 Pro (22H2) (2nd PC is 22H2)
       #4

    So your question becomes
    If I merged the registry file, would the effect be immediate?
    Quite often registry changes require that explorer be restarted to be applied. I've not experienced what happens if you change associations by editing the registry though.

    I assume you are experiencing a change in association, and want this always to be photoviewer.
    If so, the question then is - what is changing your association?

    Otherwise perhaps you could state the perceived problem you're trying to solve.
    Last edited by dalchina; 01 Mar 2018 at 06:04.
      My Computers


  5. Posts : 7
    Windows 10
    Thread Starter
       #5

    So I've found the solution to associate with Windows Photo Viewer instantly without restarting PC. But you need to uninstall UWP photo app before.
    Code:
    Get-AppxPackage -AllUsers | Where-Object name -CNotLike *Store* | Remove-AppxPackage -ErrorAction SilentlyContinue
    Get-AppxProvisionedPackage -Online | Where-Object DisplayName -CNotLike *Store* | Remove-AppxProvisionedPackage -Online -ErrorAction SilentlyContinue
    
    IF (!(Test-Path Registry::HKEY_CLASSES_ROOT\Applications\photoviewer.dll\shell\open\command))
    {
        New-Item -Path Registry::HKEY_CLASSES_ROOT\Applications\photoviewer.dll\shell\open\command -Force
    }
    IF (!(Test-Path Registry::HKEY_CLASSES_ROOT\Applications\photoviewer.dll\shell\open\DropTarget))
    {
        New-Item -Path Registry::HKEY_CLASSES_ROOT\Applications\photoviewer.dll\shell\open\DropTarget -Force
    }
    IF (!(Test-Path Registry::HKEY_CLASSES_ROOT\Applications\photoviewer.dll\shell\print\command))
    {
        New-Item -Path Registry::HKEY_CLASSES_ROOT\Applications\photoviewer.dll\shell\print\command -Force
    }
    IF (!(Test-Path Registry::HKEY_CLASSES_ROOT\Applications\photoviewer.dll\shell\print\DropTarget))
    {
        New-Item -Path Registry::HKEY_CLASSES_ROOT\Applications\photoviewer.dll\shell\print\DropTarget -Force
    }
    New-ItemProperty -Path Registry::HKEY_CLASSES_ROOT\Applications\photoviewer.dll\shell\open -Name MuiVerb -Type String -Value "@photoviewer.dll,-3043" -Force
    New-ItemProperty -Path Registry::HKEY_CLASSES_ROOT\Applications\photoviewer.dll\shell\open\command -Name "(Default)" -Type ExpandString -Value "%SystemRoot%\System32\rundll32.exe `"%ProgramFiles%\Windows Photo Viewer\PhotoViewer.dll`", ImageView_Fullscreen %1" -Force
    New-ItemProperty -Path Registry::HKEY_CLASSES_ROOT\Applications\photoviewer.dll\shell\open\DropTarget -Name Clsid -Type String -Value "{FFE2A43C-56B9-4bf5-9A79-CC6D4285608A}" -Force
    New-ItemProperty -Path Registry::HKEY_CLASSES_ROOT\Applications\photoviewer.dll\shell\print\command -Name "(Default)" -Type ExpandString -Value "%SystemRoot%\System32\rundll32.exe `"%ProgramFiles%\Windows Photo Viewer\PhotoViewer.dll`", ImageView_Fullscreen %1" -Force
    New-ItemProperty -Path Registry::HKEY_CLASSES_ROOT\Applications\photoviewer.dll\shell\open\DropTarget -Name Clsid -Type String -Value "{60fd46de-f830-4894-a628-6fa81bc0190d}" -Force
    
    cmd.exe /c 'ftype Paint.Picture=%windir%\System32\rundll32.exe "%ProgramFiles%\Windows Photo Viewer\PhotoViewer.dll", ImageView_Fullscreen %1'
    cmd.exe /c 'ftype jpegfile=%windir%\System32\rundll32.exe "%ProgramFiles%\Windows Photo Viewer\PhotoViewer.dll", ImageView_Fullscreen %1'
    cmd.exe /c 'ftype pngfile=%windir%\System32\rundll32.exe "%ProgramFiles%\Windows Photo Viewer\PhotoViewer.dll", ImageView_Fullscreen %1'
    cmd.exe /c 'ftype TIFImage.Document=%windir%\System32\rundll32.exe "%ProgramFiles%\Windows Photo Viewer\PhotoViewer.dll", ImageView_Fullscreen %1'
    cmd.exe /c "assoc .bmp=Paint.Picture"
    cmd.exe /c "assoc .jpg=jpegfile"
    cmd.exe /c "assoc .jpeg=jpegfile"
    cmd.exe /c "assoc .png=pngfile"
    cmd.exe /c "assoc .tif=TIFImage.Document"
    cmd.exe /c "assoc .tiff=TIFImage.Document"
    cmd.exe /c "assoc Paint.Picture\DefaultIcon=%SystemRoot%\System32\imageres.dll,-70"
    cmd.exe /c "assoc jpegfile\DefaultIcon=%SystemRoot%\System32\imageres.dll,-72"
    cmd.exe /c "assoc pngfile\DefaultIcon=%SystemRoot%\System32\imageres.dll,-71"
    cmd.exe /c "assoc TIFImage.Document\DefaultIcon=%SystemRoot%\System32\imageres.dll,-122"
      My Computer


 

  Related Discussions
Our Sites
Site Links
About Us
Windows 10 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 10" and related materials are trademarks of Microsoft Corp.

© Designer Media Ltd
All times are GMT -5. The time now is 00:36.
Find Us




Windows 10 Forums