Opening a browser using system.disgnostics.process class

  • Thread starter Thread starter Shawn Hogan
  • Start date Start date
S

Shawn Hogan

I'm trying to open an instance of the default browser and browse to a URL.

I'm seeing an issue with the process class where if i execute my process
using this code
Dim p As Process = New Process
p.StartInfo.Arguments = "www.starwars.com"
p.StartInfo.FileName = "iexplore.exe"
p.Start()
p.CloseMainWindow()
Dim c As Boolean = p.HasExited

i can consume events and access properties of the process class after i
execute start(like closemainwindow). When i use the code below i cannot
reference properties of the process class.

Dim q As New Process
q.Start("www.starwars.com")
p.CloseMainWindow()
Dim b As Boolean = q.HasExited

Anyone have any ideas as to why this is the case. Additionally i'd also like
to know if there is a way to get the exe path of the default browser.

Thanks,
Shawn
 
Hi Shawn,

I'm guessing that you can't consume the events when you pass an url as
process parameter because windows is responsible for launching the web
browser.

As for the path to the default web browser, I don't know.
You can obtain the paths to various web browsers using

HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\App Paths\

and the individual IEXPLORE.EXE, OPERA.EXE
Also, just passing "iexplore.exe" as a process parameter may not always
work and you should use the full path instead.
 
Back
Top