ShellExecute() - make IE open in a new window?

Started by
4 comments, last by Michalson 19 years, 1 month ago
Quick question: Is it possible to make Internet Explorer open in a new window via the command line? I tried:

#include <windows.h>

INT WINAPI WinMain( HINSTANCE hInstance, HINSTANCE, LPSTR, INT )
{
	ShellExecute( NULL, "open", "C:\Program Files\Internet Explorer\iexplore.exe -new", NULL, NULL, SW_SHOWNORMAL);
	return 0;
}

Unfortunately, that steals any presently opened window and steals whatever is open there. Is there an alternative method? All I want is for it to get a new brower window. Any help would be appreciated.
.:<<-v0d[KA]->>:.
Advertisement
I got it to work well with CreateProcess:

	STARTUPINFO si = { 0, };	si.cb = sizeof( STARTUPINFO );	PROCESS_INFORMATION pi = { 0, }, pi2 = { 0, };	CreateProcess( "c:\\Program Files\\Internet Explorer\\iexplore.exe", "iexplore.exe", NULL, NULL, FALSE,		NORMAL_PRIORITY_CLASS, NULL, NULL, &si, &pi );	CreateProcess( "c:\\Program Files\\Internet Explorer\\iexplore.exe", "iexplore.exe www.google.com", NULL, NULL, FALSE,		NORMAL_PRIORITY_CLASS, NULL, NULL, &si, &pi2 );


May I ask why you must use Internet Explorer? I know some people find it annoying to have a program open up IE instead of their default browser.

[edit] I just noticed you didn't escape your backslashes ("\" instead of "\\"). Is this just for the example?

[edit2] Try putting -new in the lpParameters argument of the ShellExecute function (if you must use -new).


Regards,
jflanglois
the best way to do this IMHO, is to use shellexecute like this

ShellExecute( NULL, "open", "HTTP://www.google.com.au", NULL, NULL, SW_SHOWNORMAL);

that way it will use the default browser on the machine instead of spawning a specific one. I'd hate it if a program opened IE instead of firefox :)
This isn't a program I'm planning to release. It's simply a time saver feature I'm hoping to implement. For example, I need dictionary.com often, and I was hoping to have my program run in the background, so I could use some quick keyboard shortcut to bring up a text prompt. All I'd have to do is enter the word, and the program would retrieve the defenitions. The implementation comes later, but for now I was hoping to get the basics down [smile].

As for double backslashes - wow, I just noticed that too! It worked fine for some strange reason. But then again, I'm using buggy old VC++ 6.0 still, so...
.:<<-v0d[KA]->>:.
Quote:Original post by v0dKA
Quick question: Is it possible to make Internet Explorer open in a new window via the command line?


What OS are u running?
ShellExecute(NULL,"c:\\program files\\internet explorer\iexplore.exe", NULL, SW_SHOWNORMAL) works fine for me in XP.
The problem is not how you are executing. The problem is that you are trying to override user settings in IE. In IE, go to tools, options, and uncheck the "Reuse windows for launching shortcuts". *That* is the correct method of controlling whether IE creates a new Window or uses the last focused one to launch shell requests(like when you double click a jpeg file)

This topic is closed to new replies.

Advertisement