• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 363
  • Last Modified:

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)
0
paulstamp
Asked:
paulstamp
  • 7
  • 6
  • 6
  • +2
1 Solution
 
AzraSoundCommented:
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
0
 
mark2150Commented:
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
0
 
IsaacRUCommented:
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")
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
KDivadCommented:
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...)
0
 
paulstampAuthor Commented:
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
0
 
paulstampAuthor Commented:
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 ?
0
 
AzraSoundCommented:
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>
0
 
AzraSoundCommented:
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.
0
 
mark2150Commented:
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
0
 
paulstampAuthor Commented:
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.

0
 
KDivadCommented:
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.
0
 
AzraSoundCommented:
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.
0
 
IsaacRUCommented:
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.
0
 
paulstampAuthor Commented:
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.

0
 
KDivadCommented:
<<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...
0
 
KDivadCommented:
<<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>>
I believe FindExecutable finds the default app for a file. The one that is triggered when you double-click a file.
0
 
AzraSoundCommented:
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.

0
 
paulstampAuthor Commented:
That looks like a good alternative. I'm not familiar with that API but It looks like the one I want.
0
 
paulstampAuthor Commented:
Thanks for your contributions everybody.
0
 
AzraSoundCommented:
umm did you even try that code?
0
 
KDivadCommented:
<<(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)?)).
0
 
AzraSoundCommented:
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
0
 
KDivadCommented:
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.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 7
  • 6
  • 6
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now