2

I'm trying to figure out how File Explorer is able to open files in specific programs (context menu => open with), in particular installed UWP (Appx) Microsoft store apps, so that I can do this via Powershell.

See this thread for more details: How to open installed Microsoft Store apps from powershell?

In that thread we figured that you can launch installed UWP apps with arguments as follows:

Start-Process ('shell:AppsFolder\' + (Get-AppXPackage *Edge*)[-1].PackageFamilyName + '!App') -ArgumentList 'http://example.org https://wikipedia.org'

However, it seems that apps like "Photos" and "VLC" don't just open the files passed as arguments:

Start-Process ('shell:AppsFolder\' + (Get-AppXPackage *Photos*).PackageFamilyName + '!App') -ArgumentList 'C:\test\image1.png'
Start-Process ('shell:AppsFolder\' + (Get-AppXPackage *VLC*).PackageFamilyName + '!App') -ArgumentList 'C:\test\audio1.mp3'

The @mklement0 in the mentioned thread figured it's probably using COM: \HKEY_CLASSES_ROOT\jpegfile\ShellEx\{e357fccd-a995-4576-b01f-234630154e96} and %SystemRoot%\system32\PhotoMetadataHandler.dll

I have little experience with powershell / COM / DLL, so I'm not sure how to apply this information.

Questions

Is there a general way to open any file (any extension) passed as an argument (or otherwise) in a specified UWP app with Powershell (or C# as the last resort)?

And if that's easy to do can you also suggest a way to get a list of apps that support the specified file type / extension? (the same way File Explorer's "Open with" menu does it)

AlekseyHoffman
  • 2,438
  • 1
  • 8
  • 31
  • The registry key you found belongs to a [Thumbnail Handler](https://learn.microsoft.com/en-us/previous-versions/windows/desktop/legacy/cc144118(v=vs.85)). The [docs](https://learn.microsoft.com/en-us/windows/win32/shell/fa-file-types#registering-a-file-type) may help further. As of opening a file with a specific UWP apps - I have no idea. Is there nothing helpful in the command line column in the Task Manager? – Steeeve Aug 24 '21 at 18:49
  • Thanks for the info. The processes of UWP apps don't seem to have any process arguments specified in the task manager – AlekseyHoffman Aug 24 '21 at 19:00

1 Answers1

2

The following doesn't directly answer your question, but may still be helpful:

If you take a document-centric (file-type-centric) view:

  • You can directly pass a document (non-executable) to Start-Process, which uses the Windows shell's Open verb to process the document by default (the same operation you'd get if you double-clicked the document in File Explorer, for instance). The -Verb parameter allows you to select a different verb; e.g., to invoke the Edit verb on a batch file (*.cmd), which opens it for editing:

    Start-Process -Verb Edit some.cmd
    
  • To determine the available verbs for a given document (file type), use the following (note that the specified file needn't exist - what matters is the file-name extension):

    [System.Diagnostics.ProcessStartInfo] @{ FileName = 'foo.cmd' }
    
    • Note:
      • runas and runasuser are standard verbs that aren't file-type-specific and refer to performing an operation with elevation (as admin) and as a different (non-admin) user, respectively.
      • Open isn't always explicitly listed, but it is implicitly available - which in the case of file types without an associated application displays a dialog offering to select one or download one from the Microsoft Store (the dialog has no GUI element for dismissing (closing) it, but you can simply press Esc).
mklement0
  • 382,024
  • 64
  • 607
  • 775
  • 1
    Thanks for the info. The print verb seems quite useful, I might use that. But I think I'll have to write a native .NET / C# / C++ module or executable for these kind of native operations anyway. I will also need a way to trigger native Win 10 sharing dialog, which will also require some native calls, I think there's no way around it, it seems that Powershell is just not the tool for these kind of operations – AlekseyHoffman Aug 25 '21 at 23:07