0
votes

In my application there is an interface where user can select any file and open in its default application depending on the file association.

I am using FindExecutable and CreateProcessAsUser with Explorer token.

Now the problem is in the case of picture files say .jpg, FindExecutable returns "C:\Program Files\Windows Photo Gallery\PhotoViewer.dll", then CreateProcessAsUser returns "ERROR_BAD_EXE_FORMAT(193) %1 is not a valid Win32 application.". I was passing NULL as the second parameter for CreateProcessAsUser, sending executable path in lpCommandLine(eg: CreateProcessAsUser(hToken, NULL, szCmdline, ...)).

Can anyone help me in solving this?

Regards, Manoj

2

2 Answers

1
votes

A Win32 executable has extension .EXE; a DLL is not an executable. CreateProcess cannot create a process with just a .DLL. The missing .EXE is "rundll32.exe".

However, that's not what you are after: you want the Shell behavior. ShellExecuteEx() is usually the most convenient function. AssocQueryString() may be appropriate in this case, with the right flags: ASSOCSTR_EXECUTABLE to get the executable in case it's not yet running, and ASSOCSTR_DDEAPPLICATION etc. in case the application already runs.

0
votes

how about using ShellExecuteEx with a properly initialized structure? This should invoke the default action on a given file.