Solved

Shell Execute / Multiple Instancing

Posted on 2000-04-27
23
327 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
ID: 2755853
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
ID: 2755918
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
ID: 2756150
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
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 
LVL 5

Expert Comment

by:KDivad
ID: 2757171
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
ID: 2758419
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
ID: 2758425
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
ID: 2758440
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
ID: 2758449
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
ID: 2758851
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
ID: 2759705
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
ID: 2760432
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
 
LVL 28

Expert Comment

by:AzraSound
ID: 2760446
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
ID: 2760524
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
ID: 2760978
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
ID: 2761351
<<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
ID: 2761356
<<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
ID: 2761442
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
ID: 2761708
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
ID: 2761710
Thanks for your contributions everybody.
0
 
LVL 28

Expert Comment

by:AzraSound
ID: 2761711
umm did you even try that code?
0
 
LVL 5

Expert Comment

by:KDivad
ID: 2761738
<<(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
ID: 2761763
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
ID: 2761780
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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

776 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