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.
Call
ShellExecuteExand specify thelpClassmember of theSHELLEXECUTEINFOstruct. Note that you must includeSEE_MASK_CLASSNAMEin thefMaskmember.For instance, set
lpClassto'.txt'to request that the file be opened with the program associated with the.txtextension.