Open in Explorer


How do you open a path in explorer by code in c++. I googled and couldn’t find any thing but systems commands to do this, however, i dont want it to block or show the console window.


You probably are looking for the ShellExecute() function in shellapi.h. It is called with an "action verb", a path, and optional parameters. In your case this will want either "open" or "explore" as follows:

ShellExecuteA(NULL, "open", "C:\\", NULL, NULL, SW_SHOWDEFAULT);

This will open an unattached explorer window at C:. ShellExecute() will give basically the same action as typing in a command at the Run dialog. It will also handle URLs, so the following will open up the user’s default browser:

ShellExecuteA(NULL, "open", "", NULL, NULL, SW_SHOWDEFAULT);

Although make sure to pay attention to the note in the documentation that ShellExecute relies on COM (Although your code doesn’t have to worry about any COM objects itself).


Answered By – ScottF

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published