Finding the default app for a file type (Win 10)

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
wpb
Posts: 146
Joined: 14 Dec 2015, 01:53

Finding the default app for a file type (Win 10)

23 Oct 2017, 04:13

Hi there,
I've read around on the forums and Google about this for some time, but I'm now at a brick wall. I'm hoping someone can help.
I'm trying to find out the default app that runs when you double click on a jpeg file. In fact, I want the command line that's called.

I've done this successfully for other filetypes. I use AssocQueryString, requesting ASSOCSTR_COMMAND (1) in the second parameter to get the command line I'm interested in.

With .jpg files, this does nothing. If I set the ASSOCF_REMAPRUNDLL flag, and request ASSOCSTR_DELEGATEEXECUTE (18) instead, I get a CLSID back. ({4ED3A719-CEA8-4BD9-910D-E252F997AFC2}) If I look that up in the registry at HKEY_CLASSES_ROOT\CLSID\%CLSID_I_got%\InProcServer32, I can find a dll reference to twinui.dll (%SystemRoot%\system32\twinui.dll), which is indeed the "app" (I know it's a dll) that's set to "open" when I double click on a jpg file at the moment on my system.

But I don't know how to run that dll. Rundll with that path does nothing.

My end game is: I want to open a picture file in the default viewer for the system, but that file might not have a picture file extension. So I want to send it to the picture viewer app using a command line.

Any help would be much appreciated.
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Finding the default app for a file type (Win 10)

23 Oct 2017, 12:39

Windows Photo Viewer uses a dll, and this worked for me, so something similar might work for twinui.dll. Also, I've provided a script to get the app path for an extension. Also, if you run the program in the normal way, you can retrieve its command line while it's open. And if there's a lnk file somewhere, e.g. in the Start menu, you could inspect that.

Code: Select all

q:: ;image open with Windows Photo Viewer
RegRead, vPath, HKEY_CURRENT_USER\Control Panel\Desktop, Wallpaper
Run, rundll32.exe "%A_ProgramFiles%\Windows Photo Viewer\PhotoViewer.dll"`, ImageView_Fullscreen %vPath%
return

;==================================================

w:: ;extension get app path
;ASSOCSTR_EXECUTABLE = 2 ;app path
vExt := ".jpeg"
DllCall("shlwapi\AssocQueryString", Int,0, Int,2, Str,vExt, Ptr,0, Ptr,0, UIntP,vChars)
VarSetCapacity(vPath, vChars << !!A_IsUnicode, 0)
DllCall("shlwapi\AssocQueryString", Int,0, Int,2, Str,vExt, Ptr,0, Str,vPath, UIntP,vChars)
MsgBox, % vPath
return

;==================================================

e:: ;process get command line
WinGet, vPID, PID, A
oWMI := ComObjGet("winmgmts:")
oQueryEnum := oWMI.ExecQuery("Select * from Win32_Process where ProcessId=" vPID)._NewEnum()
if oQueryEnum[oProcess]
	vCmdLn := oProcess.CommandLine
oWMI := oQueryEnum := oProcess := ""
MsgBox, % vCmdLn
return
Last edited by jeeswg on 10 Dec 2017, 13:19, edited 1 time in total.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
wpb
Posts: 146
Joined: 14 Dec 2015, 01:53

Re: Finding the default app for a file type (Win 10)

23 Oct 2017, 15:16

Thanks for this, jeeswg. Your rundll23 line is almost exactly what I have already tried, and sadly it just gives:
There was a problem starting %SystemRoot%\system32\twinui.dll

The specified module could not be found.
So it seems twinui.dll can't be invoked in the same way as PhotoViewer.dll.

Your AssocQueryString code is also almost exactly what I have. For .jpeg on my system, it returns a null string. Even though .jpeg is associated with jpegfile in Assoc, jpegfile doesn't appear in the output of ftype at all! Yet jpeg files DO load happily into Photo when double-clicked in Explorer.

The idea to get the command line from the app when it was normally invoked was great, but sadly it just returns this:
C:\WINDOWS\system32\ApplicationFrameHost.exe -Embedding
That's not overly useful as far as I can tell!

So thanks very much for the input, but I don't think I'm any closer to solving this conundrum. I had no idea filetype associations could be so tricky!
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Finding the default app for a file type (Win 10)

23 Oct 2017, 15:24

What string do you get if you do this? And have you seen any references online to people using this program/dll to open an image?

Also, what is the name of the program, is it called something like image viewer? What is the class, and what is the text of a typical window title?

Perhaps also, what exe files contain 'run' or 'app' in C:\Windows\System32?

Btw does my 'image open with Windows Photo Viewer' code work in Windows 10?

Code: Select all

q::
;ASSOCSTR_COMMAND := 1
vExt := ".jpeg"
DllCall("shlwapi\AssocQueryString", Int,0, Int,1, Str,vExt, Ptr,0, Ptr,0, UIntP,vChars)
VarSetCapacity(vTarget, vChars << !!A_IsUnicode, 0)
DllCall("shlwapi\AssocQueryString", Int,0, Int,1, Str,vExt, Ptr,0, Str,vTarget, UIntP,vChars)
Clipboard := vTarget
MsgBox, % vTarget
return
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
wpb
Posts: 146
Joined: 14 Dec 2015, 01:53

Re: Finding the default app for a file type (Win 10)

24 Oct 2017, 05:42

What string do you get if you do this? And have you seen any references online to people using this program/dll to open an image?
AssocQueryString just gives a null string, unless I pass 18 as the second parameter, in which case I get a CLSID back (see my original post). That CLSID corresponds to the twinui.dll. There's an interesting article about twinui here: https://www.ctrl.blog/entry/what-is-twinui
Also, what is the name of the program, is it called something like image viewer? What is the class, and what is the text of a typical window title?
It's called "Photos", and it displays "blah_blah.jpg - Photos" in the title bar area. ahk_class ApplicationFrameWindow, ahk_exe ApplicationFrameHost.exe
Perhaps also, what exe files contain 'run' or 'app' in C:\Windows\System32?
I haven't got around to this yet...
Btw does my 'image open with Windows Photo Viewer' code work in Windows 10?
Yes, that still works in Win10. If Windows Photo Viewer was my default app, I'd have no trouble. But I'd like code that works on anyone's system, so I really need to get at the default association for jpg files, and Win10 is making that incredibly hard to do!

Thanks again for taking the time to think about this!
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Finding the default app for a file type (Win 10)

24 Oct 2017, 14:14

Some ideas:

Process watching (I don't think this will necessarily help, but it's worth mentioning):

[get notified when processes start/end]
New Process Notifier - Scripts and Functions - AutoHotkey Community
https://autohotkey.com/board/topic/5698 ... -notifier/

Watch new processes appear in Task Manager.

Run the process and try to retrieve information.

Code: Select all

q::
DetectHiddenWindows, On
vPath := "C:\MyImage.jpeg"
;Run, rundll32.exe "%A_ProgramFiles%\Windows Photo Viewer\PhotoViewer.dll"`, ImageView_Fullscreen %vPath%,,, vPID
Run, % vPath,,, vPID
oWMI := ComObjGet("winmgmts:")
oQueryEnum := oWMI.ExecQuery("Select * from Win32_Process where ProcessId=" vPID)._NewEnum()
if oQueryEnum[oProcess]
	vCmdLn := oProcess.CommandLine
oWMI := oQueryEnum := oProcess := ""
WinGet, vPPath, ProcessPath, % "ahk_pid " vPID
MsgBox, % Format("pid: {}`r`npath: {}`r`ncommand line:", vPID, vPPath, vCmdLn)
return
==================================================

[list a dll's functions, do this for twinui.dll]
DllListExports() - List of Function exports of a DLL - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=6&t=4563

Code: Select all

q::
vPath = %A_ProgramFiles%\Windows Photo Viewer\PhotoViewer.dll
vText := DllListExports(vPath)
Clipboard := StrReplace(vText, "`n", "`r`n") "`r`n"
return
And then perhaps we can try something similar to:

Code: Select all

Run, rundll32.exe "%A_ProgramFiles%\Windows Photo Viewer\PhotoViewer.dll"`, ImageView_Fullscreen %vPath%
==================================================

Get info from the registry.
E.g. HKEY_CLASSES_ROOT\.txt
points to: HKEY_CLASSES_ROOT\txtfile
E.g. check: HKEY_CLASSES_ROOT\txtfile\shell\open\command

==================================================

Launch via an object? Maybe there is a way using AHK's ComObjXXX functions to launch the process with a particular file.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Finding the default app for a file type (Win 10)

10 Dec 2017, 13:43

I've since found some potentially useful information:

What Is “Application Frame Host” and Why Is It Running on My PC?
https://www.howtogeek.com/325127/what-i ... -on-my-pc/
winapi - How to identify Windows 10 background store processes that have non-displayed windows that are programmatically visible and minimizable? - Stack Overflow
https://stackoverflow.com/questions/321 ... splayed-wi
c++ - Name of process for active window in Windows 8/10 - Stack Overflow
https://stackoverflow.com/questions/323 ... ndows-8-10

Here is an example exe path:
C:\Program Files\WindowsApps\Microsoft.BingWeather_4.5.168.0_x86__8wekyb3d8bbwe\ Microsoft.Msn.Weather.exe

So perhaps it's worth checking in C:\Program Files\WindowsApps for an exe whose name contains 'Photos'.

Btw, is there any shortcut to 'Photos' or 'Calc'/'Calculator' anywhere, that might have a path.

I'd appreciate if any Windows 10 users could explore this issue a bit. Thanks.

[EDIT:] A web search suggests that Calculator and Photos are both stored in C:\Program Files\WindowsApps.

[EDIT:] Some more related info:
Where is Microsoft Edge located in Windows 10? How do I launch it? - Super User
https://superuser.com/questions/950435/ ... -launch-it

E.g. C:\Windows\SystemApps\Microsoft.MicrosoftEdge_8wekyb3d8bbwe

E.g. %windir%\explorer.exe shell:Appsfolder\Microsoft.MicrosoftEdge_8wekyb3d8bbwe!MicrosoftEdge

[EDIT:] Another link:
WinGetMinMax false detection windows 10 - AutoHotkey Community
https://autohotkey.com/boards/viewtopic ... 37&t=40800
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Finding the default app for a file type (Win 10)

18 Dec 2017, 04:28

Any good for special Windows 10 apps? List 'New' menu items.

ShellMenuNew - Disable/enable 'New' menu items in Windows Explorer
https://www.nirsoft.net/utils/shell_menu_new.html
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: wilkster and 132 guests