Solved

Shell Execute / Multiple Instancing

Posted on 2000-04-27
23
323 Views
Last Modified: 2012-08-13
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
Comment
Question by:paulstamp
  • 7
  • 6
  • 6
  • +2
23 Comments
 
LVL 28

Expert Comment

by:AzraSound
Comment Utility
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
 
LVL 12

Expert Comment

by:mark2150
Comment Utility
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
 

Expert Comment

by:IsaacRU
Comment Utility
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
 
LVL 5

Expert Comment

by:KDivad
Comment Utility
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
 
LVL 3

Author Comment

by:paulstamp
Comment Utility
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
 
LVL 3

Author Comment

by:paulstamp
Comment Utility
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
 
LVL 28

Expert Comment

by:AzraSound
Comment Utility
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
 
LVL 28

Expert Comment

by:AzraSound
Comment Utility
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
 
LVL 12

Expert Comment

by:mark2150
Comment Utility
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
 
LVL 3

Author Comment

by:paulstamp
Comment Utility
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
 
LVL 5

Expert Comment

by:KDivad
Comment Utility
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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 28

Expert Comment

by:AzraSound
Comment Utility
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
 

Expert Comment

by:IsaacRU
Comment Utility
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
 
LVL 3

Author Comment

by:paulstamp
Comment Utility
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
 
LVL 5

Expert Comment

by:KDivad
Comment Utility
<<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
 
LVL 5

Accepted Solution

by:
KDivad earned 75 total points
Comment Utility
<<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
 
LVL 28

Expert Comment

by:AzraSound
Comment Utility
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
 
LVL 3

Author Comment

by:paulstamp
Comment Utility
That looks like a good alternative. I'm not familiar with that API but It looks like the one I want.
0
 
LVL 3

Author Comment

by:paulstamp
Comment Utility
Thanks for your contributions everybody.
0
 
LVL 28

Expert Comment

by:AzraSound
Comment Utility
umm did you even try that code?
0
 
LVL 5

Expert Comment

by:KDivad
Comment Utility
<<(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
 
LVL 28

Expert Comment

by:AzraSound
Comment Utility
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
 
LVL 5

Expert Comment

by:KDivad
Comment Utility
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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now