RSS LJ

January 17, 2007

HOWTO: launch a web browser from a win32 app ()

by fluffy at 12:01 PM
I needed to know this for a simple app at work and, not being a Win32 programmer, I couldn't find it documented, so to hopefully save someone else a wild goose chase:
ShellExecute(NULL, "open", url, NULL, NULL, SW_SHOWNORMAL);
where url is an ordinary char* string.

Comments

#8203 01/17/2007 01:04 pm heh
Yeah, that's pretty well known.

Note that it opens your default browser.

Also...I hope you're validating input, because an URL of "file://Program Files/RootkitInstall.exe" won't open the browser... Smile
#8204 01/17/2007 01:10 pm Addendum
What that call actually does is say "run the default 'open' method for the object, (the exact method depends on the mime type and/or file extension.)

For extra fun, you could use things like 'edit' or 'print'.
#8205 01/17/2007 02:49 pm
If it's so well-known, then why did it take me half an hour to figure it out? (And why did I keep on finding crap like "try system("rundll32.exe,blahblahblah url");" which didn't work in certain circumstances?)

also the URLs are generated by the app, which is only used internally anyway.