Library code snippets
Launch a PC's default browser
Often, you may want a user to access a specific URI on the Web by
launching his default browser and navigating to the Web site of your
choice. Fortunately, a simple Windows API function ShellExecute() lets
you do just that. When you pass this function a filename, it uses the
Windows file associations to start the appropriate application. As a
result, all you need do is pass this function a URI, and it automatically
launches the default browser and navigates to the requested location.
The ShellExecute() function conforms to the following syntax:Private Declare Function ShellExecute Lib _
"shell32.dll" Alias "ShellExecuteA"
_
(ByVal hWnd As Long, ByVal lpOperation _
As String, ByVal lpFile As String, ByVal _
lpParameters As String, ByVal lpDirectory _
As String, ByVal nShowCmd As Long) As Long
As you can see, it takes quite a few parameters, but don't worry, for our
purposes only two concern us: lpFile and nShowCmd. The lpFile parameter
holds the name of the file or application you want to launch, while the
nShowCmd parameter contains directions indicating how you want the
application to appear when it opens. Typically, you'll use the SW_SHOWNORMAL
constant (1).
So for instance, to use this function to navigate to a Web page with the
URI www.google.com, you'd write code along the lines of:
ShellExecute 0&, vbNullString, "www.google.com", vbNullString,
_
vbNullString, SW_SHOWNORMAL
If for any reason the ShellExecute() doesn't execute the application
properly, the function returns a value less than or equal to 32. Otherwise,
it returns a value that points to the launched application.
Related articles
Related discussion
-
Run-time error '91'
by converter2009 (1 replies)
-
VB6 Runtime error 381 subsript out of range Error
by Uncle (2 replies)
-
passing and reading parameters from using Shell
by jigartoliya (0 replies)
-
Convert C++ code to VB6
by mawcot (4 replies)
-
listbox scrollbar
by Dennijr (10 replies)
Related podcasts
-
Christian Beauclair
14 mai 2008 (�mission #0074) ::.Christian Beauclair: Stratégies de migration VB6 vers .NET Nous discutons avec Christian Beauclair des stratégies de migration VB6 vers .NET. Entre autres, nous discutons comment utiliser le "VB 6 Code Advisor" et le "Interop Forms Toolkit" pour ajouter la puiss...
This will work, but if you need more flexability and maybe need to post some data, this will allow it. You will need to add a refference to Microsoft Internet Control for it to work.
The problem with this is that it always opens internet explorer, but the beauty is that you can post data, which means you can auto log users into a site
SHDocVw.InternetExplorerClass ie=new SHDocVw.InternetExplorerClass ();
Object vHeaders = null;
Object vPost = wm.PostDataByte;
Object vTarget = null;
Object vFlags = null;
ie.Navigate(wm.PostURL,ref vFlags,ref vTarget,ref vPost,ref vHeaders);
ie.Visible =true;
if i use vb.net, do all the clients need to install the .net framework?
im using vb6, is there another way doing the same thing?
using sell excecute is not good enougth, so someone plz help me
try this:
Dim myTargetURL As String = "http://www.google.com"
System.Diagnostics.Process.Start(myTargetURL)
No declarations, etc.. works to launch the default browser whatever that is....
But suppose the user doesn't run IE? GASP How are we to know where the default browser is?
Change your code to:
Call ShellExecute(0&, vbNullString, "www.google.com", vbNullString, _
vbNullString, SW_SHOWNORMAL)
This thread is for discussions of Launch a PC's default browser.