In my application, I would like to be able to execute a file with an arbitrary name and extension using the program associated with a different extension.
For example, say I have a file called file.dat
, but I wanted to open it with Notepad, as if it was named file.txt
or file.dat.txt
. Also, I don't have permission to rename the file, so that's out of the question.
If the file were called file.txt
, I could call ShellExecute. But that fails when calling file.dat
; Windows complains that there’s no association for that file.
I don't want to hardcode a specific executable, because (in the example above) the end user could have associated .txt
files with Wordpad instead of Notepad. In such a case, I’d want my file.dat
to be opened with Wordpad.
Open File Manager and browse the the folder containing the files that you want to associate with a particular app. This will set the target file types to be opened with the selected app and open that file in that app as well. By the way doing things in Android is not too difficult.
File associations are registry settings that tell Windows what application to use to open files of a certain type. For example, Windows typically launches Notepad.exe when a text (. txt) file is opened.
To be more precise, run the app (no installation needed), choose File Type Settings -> click Context Menu -> find your extension -> click Next -> choose Open -> click Edit Selected Command... -> clear the Program path -> click Next -> click Save Context Menu.
Call ShellExecuteEx
and specify the lpClass
member of the SHELLEXECUTEINFO
struct. Note that you must include SEE_MASK_CLASSNAME
in the fMask
member.
For instance, set lpClass
to '.txt'
to request that the file be opened with the program associated with the .txt
extension.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With