Reputation: 703
I have a program written in C++ which does some computer diagnostics. Before the program exits, I need it to launch Internet Explorer and navigate to a specific URL. How do I do that from C++? Thanks.
Upvotes: 4
Views: 13547
Reputation: 71
Try this system("\"C:\Program Files\Internet Explorer\iexplore\" http://www.shail.com"); Works perfectly..
Upvotes: 0
Reputation: 31
Do you really need to launch IE or just some content in a browser? The ShellExecute
function will launch whatever browser is configured to be the default. Call it like this:
ShellExecute(NULL, "open", szURL, NULL, NULL, SW_SHOW);
Upvotes: 3
Reputation: 43
include <windows.h>
int main()
{
ShellExecute(0, "open",
"C:\\progra~1\\intern~1\\iexplore.exe",
"http://www.foo.com",
"",
SW_MAXIMIZE);
return 0;
}
Upvotes: 3
Reputation:
if you really need to launch internet explorer you should also look into using CoCreateInstance(CLSID_InternetExplorer, ...) and then navigating. depending on what else you want to do it might be a better option.
Upvotes: 3
Reputation: 44804
I'm with Glen and John, except I'd prefer to use CreateProcess instead. That way you have a process handle you can do something with. Examples might be Kill IE when you are done with it, or have a thread watching for IE to terminate (WaitForSingleObject with the process handle) so it could do something like restart it, or shut down your program too.
Upvotes: 2
Reputation: 10732
Here you are... I am assuming that you're talking MSVC++ here...
// I do not recommend this... but will work for you
system("\"%ProgramFiles%\\Internet Explorer\\iexplore.exe\"");
// I would use this instead... give users what they want
#include <windows.h>
void main()
{
ShellExecute(NULL, "open", "http://stackoverflow.com/questions/982266/launch-ie-from-a-c-program", NULL, NULL, SW_SHOWNORMAL);
}
Upvotes: 9
Reputation: 22290
Using just standard C++, if iexplore is on the path then
#include <stdlib.h>
...
string foo ("iexplore.exe http://example.com");
system(foo.c_str());
If it's not on the path then you need to work out the path somehow and pass the whole thing to the system call.
string foo ("path\\to\\iexplore.exe http://example.com");
system(foo.c_str());
Upvotes: 2