Simple console program to open any file

I'm just looking for a way to open any file or exe from a command line program. It will be built into something larger.

So the user will input the file/exe location under

string file;

I was just trying with #include <windows.h> and the following
 
ShellExecute(GetDesktopWindow(), "open", file, NULL, NULL, SW_SHOWNORMAL);

But I'm sure I'm missing something.

The files will be primarily excel, pdf, reports, text files. So I could use the system() function but with that you have to tell it the type of program as well as the file location.
Windows doesn't open files, programs do. You have to tell windows which program to use or how does it know to use Notepad, wordpad, or textpad.

Now windows has a default or user chosen program for each file type but I don't know how you determine that from a command line. For example right click a txt file and you can choose which program to open that file with. Windows keeps that information in the registry. Finally, not all computers are setup the same and some programs might not be installed, or working.

The link below has some good examples including one how to check for success.

https://www.experts-exchange.com/articles/1595/Execute-a-Program-with-C.html
Topic archived. No new replies allowed.