Answered by:
HOw to open links in my browser

Question
-
Hi I have a default browser which I made, now i want it to launch when a user clicks a link in Messingers or anywhere. In IE it autoopens the Iexplore.exe WITH the url as the page. I want to do the same with my browser and so far I came to the point when it can read arguments but my problem is that the argument it reads is -nohome and Thats it..heres my code I use .. please help if theres other ways.
-----myarguments.vb
My
NamespaceClass MyApplication
Public FileToOpen As String
#If _MyType = "WindowsForms" Then
Private Sub MyApplication_Startup(ByVal sender As Object, ByVal e As ApplicationServices.StartupEventArgs) Handles Me.Startup
Try
Form1.FileToOpen = e.CommandLine(0)
Catch ex As Exception
End Try
End Sub
<Global.System.Diagnostics.DebuggerStepThrough()> _
Protected Overrides Function OnInitialize(ByVal commandLineArgs As System.Collections.ObjectModel.ReadOnlyCollection(Of String)) As Boolean
Return MyBase.OnInitialize(commandLineArgs)
End Function
#End If
End Class
End Namespace
----Form1Public Class Form1
Public FileToOpen As String
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
webbrowser1.url = new uri(filetoOpen)
end sub
end classMonday, December 22, 2008 3:10 PM
Answers
-
Your statement of
Form1.FileToOpen = e.CommandLine(0)
Is only reading in 1 of your command line params, the first one in the list.
You can use a for each loop to go through each of the command line params (parsed at spaces) so if you had
myapp.exe someparam someotherparam www.somesite.com
You could also choose to do name/value pairs like -url:www.somesite.com or url=www.somesite.com, but the parsing is still done on spaces, so if you do that, you will have to do some of your own string parsing as well.
Private Sub MyApplication_Startup(ByVal sender As Object, ByVal e As Microsoft.VisualBasic.ApplicationServices.StartupEventArgs) Handles Me.Startup For Each s As String In e.CommandLine 'S HERE IS THE CURRENT COMMAND LINE PARAM 'first value "someparam" 'second value "someotherparam" 'third value "www.somesite.com" Next End Sub
Also keep in mind that if someone else is using your app, the order or presence of command line params can be totally different each time.
Matt Kleinwaks - MSMVP MSDN Forums Moderator - www.zerosandtheone.com- Edited by kleinmaModerator Monday, December 22, 2008 4:26 PM added comment
- Proposed as answer by Reed KimbleMVP, Moderator Monday, December 22, 2008 10:05 PM
- Marked as answer by Martin Xie - MSFT Friday, December 26, 2008 9:28 AM
Monday, December 22, 2008 4:25 PMModerator
All replies
-
Your statement of
Form1.FileToOpen = e.CommandLine(0)
Is only reading in 1 of your command line params, the first one in the list.
You can use a for each loop to go through each of the command line params (parsed at spaces) so if you had
myapp.exe someparam someotherparam www.somesite.com
You could also choose to do name/value pairs like -url:www.somesite.com or url=www.somesite.com, but the parsing is still done on spaces, so if you do that, you will have to do some of your own string parsing as well.
Private Sub MyApplication_Startup(ByVal sender As Object, ByVal e As Microsoft.VisualBasic.ApplicationServices.StartupEventArgs) Handles Me.Startup For Each s As String In e.CommandLine 'S HERE IS THE CURRENT COMMAND LINE PARAM 'first value "someparam" 'second value "someotherparam" 'third value "www.somesite.com" Next End Sub
Also keep in mind that if someone else is using your app, the order or presence of command line params can be totally different each time.
Matt Kleinwaks - MSMVP MSDN Forums Moderator - www.zerosandtheone.com- Edited by kleinmaModerator Monday, December 22, 2008 4:26 PM added comment
- Proposed as answer by Reed KimbleMVP, Moderator Monday, December 22, 2008 10:05 PM
- Marked as answer by Martin Xie - MSFT Friday, December 26, 2008 9:28 AM
Monday, December 22, 2008 4:25 PMModerator -
I would do as Kleinma says and examine ALL of the command arguments.
I recognize -nohome as meaning "start without the homepage" so it looks like you are getting the default IE commands sent to your application.
For your reference, here is a technet article with the list of switches and arguments that you'll want to handle:
http://www.microsoft.com/technet/prodtechnol/windows2000serv/reskit/ierk/Ch17_h.mspx?mfr=true
Reed Kimble - "When you do things right, people won't be sure you've done anything at all"Monday, December 22, 2008 10:12 PMModerator