Link to home
Start Free TrialLog in
Avatar of paulstamp
paulstamp

asked on

Shell Execute / Multiple Instancing

I am writing an app in VB in which I generate reports in HTML and then launch a browser to display them (using ShellExecute)

My problem is that each time I use ShellExecute it recycles the current instance of IE - I would like to be able to have multiple instances at any given time.

Any suggestions ? Note - I dont want a solution which depends upon my knowing which browser is installed, so no command-line switches for iexplore.exe please !

The code I'm using is shown below :

Call ShellExecute(Me.hwnd, "open", "c:\myreport.htm", vbNullString, "c:\", sw_shownormal)
Avatar of AzraSound
AzraSound
Flag of United States of America image

you can create instances of the internet explorer object instead.  adding a reference to the microsoft internet controls you can declare it as such:

Dim IEobj As New SHDocVw.InternetExplorer

then its just like any other object you can create an array or create dynamically.
just be sure to set its visible property to true when you launch it
Avatar of mark2150
mark2150

Why not use the web browser control and show the stuff internally to your app? You can use a control array and have multiple browsers pop if that's what you want...

M
You can use this to open a new window ( Note: Be sure use the correctlocation of Iexplore.exe

Dim vReturn
vReturn = Shell("C:\Program Files\Internet Explorer\Iexplore.exe www.hotfiles.com")
My guess, but it should work (at least for IE):

Call ShellExecute(Me.hwnd, "opennew", "c:\myreport.htm", vbNullString, "c:\", sw_shownormal)

Hope this helps! (Hope it works...)
Avatar of paulstamp

ASKER

Sorry guys... most of you didnt read the question properly. I dont want an answer that depends on the browser installed so any answer along the lines of shelling IE or using create object is a no-go.

I dont want to use the browser control for 2 reasons a) - it requires IE to be installed - my understanding is that you aren't allowed to ship the control, and b) I want to limit the no. of dependencies in my app.

Kdivad's answer is more along the right lines... I'll try that out now and if it works I'll award the points
Kdivad - sorry - doesnt work.. just recycles the old window.

Interestingly Netscape does open a new window using my existing window, just not IE

I'm not sure there is going to be an answer to this as it may be browser dependent, but I would have thought something along the lines of "opennew" might work.

Any more ideas ?
a crude workaround might be to sendkeys to an open browser (ctrl + n) which opens a new window for both browsers.  then a routine using sendmessage api with wm_settext to post the desired url.  <just brainstorming>
actually, what am i thinking, doesnt the createprocess api create a new process?  i would imagine it would create a new navigator window.  i'll hafta go test it out.
You can ship IE if you get the license. It's free so it's just a formality. You can clobber the IEXPLORE.EXE file once it's installed so that they cannot manually run the browser. Then your program can use an internal window without difficulty.

M
Hmm.. still dont want to include the browser control - I want to keep my app as lightweight as possible. I work in the Oil and Gas Industry and most of our clients are some of the world's largest companies and their IT departments tend to object to people installing ActiveX's - let alone full-blown browsers with their apps!

If I can't find an answer I'll stick with what I already have which works fine, except that it means any user with IE will only get one report at a time.

I was hoping for a suggestion like KDivad's - perhaps a different command I could use with ShellExecute.

Hmm...Oh well, looks like I still need to figure out exactly how shellexecute works...

Perhaps use the FindExecutable function (API?). If it turns out to be IE, then do something that works with IE. If it's NetScape, do something that works there, etc.

Here's an interesting (though not necesarily a good) workaround:
Have a form that contains a reference to the m$ internet controls. Attempt to determine if IE exists on the system. If it does, then you can load that form safely and use the IE collection to control it's windows.
the only problem there is some people (such as myself) have both browsers installed.  i imagine paul would want to launch the user's default browser. however, if thats not a concern then this is a possibility.  i messed around with the createprocess api but was unsuccessful.  i havent had much experience with it so i cant even say if it would be a correct solution had i got it to work.
Maybe you could ask the user(s) in the setup what browsers they have on their system and the locations. Then place that information in the registry and retrive it from there whenever necessary.
Thanks guys... still not got the answer I'm looking for, but if there's no spark of inspiration from anyone in the next few days then KDivad is closest to getting the points!

I think generating HTML and ShellExecute is an elegant way of doing reports because I'm sure every system has some application capable of displaying HTML - dont forget - it doesnt even need to be a browser : Word will suffice if its associated with HTM files.

Over recent years I've become increasingly wary of shipping extra controls where it isn't absolutely necessary so the idea of using a (fairly) universal format like HTML is appealing.

Ideally I don't want to write specific code for different browsers.

As I said before... if I cant find a better solution then I'll live with what I've got at the moment. The first version of my app did use the browser control but for reasons I've already explained I'm looking for a more generic and lightweight answer.

<<Here's an interesting (though not necesarily a good) workaround:
Have a form that contains a reference to the m$ internet controls. Attempt to determine if IE exists on the system. If it does, then you can load that form safely and use the IE collection to control it's windows.>>

I thought about this while at work and realized this is something you do NOT want to do. If your app references IE and IE isn't installed then it won't run at all. (Unless the form tries GetObject and CreatObject to find IE)

How about a non-HTML workaround? You can use RTF instead. Every system that I've seen (not very many, I'll admit...) has some editor that can read these files.

Still thinking...
ASKER CERTIFIED SOLUTION
Avatar of KDivad
KDivad

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
yea i wasnt thinking to even look up findexecutable to see what it did i just kinda went by its name (thinking it just found an exe to see if it existing)  however kdivad makes a point, use that to find the default browser.  try this with shellexecute:


Dim retval As Long
    retval = ShellExecute(Me.hwnd, "Open", "C:\Program Files\Internet Explorer\Iexplore.exe", _
        "C:\Windows\Desktop\google.htm", "C:\", vbNormalFocus)


obviously those are just samples I used.  if you find the default browser is netscape point the parameter to the netscape.exe  the thing we were missing was to make use of the lparameters value.

That looks like a good alternative. I'm not familiar with that API but It looks like the one I want.
Thanks for your contributions everybody.
umm did you even try that code?
<<(thinking it just found an exe to see if it existing)>>
Nope, but interestingly enough there is an API to detemine if a file exists (SHFileExists(To see if a file exists, you can use any number of built-in capabilities)) AND one to determine if a file is executable (SHPathIsExe(Note: It doesn't check for the file's existence(or even for path/filename validity), it merely checks the extension for .exe, .com, .pif or .bat. Can anyone use Right$( , 4)?)).
well i found it a little late but here it is.  it was a combination of kdivad and I's answers, findexecutable combined with createprocess:


http://www.mvps.org/vbnet/code/fileapi/browserstart.htm
Very nice! This should answer PaulStamp's question perfectly!

I don't know, but he may give you some points for it even though he's already accepted my answer.