• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 790
  • Last Modified:

Close Browser window with VB.net

I have an application that includes a timer.  Every hour I have code which downloads a file from a website and saves it to a specific location.  The application is working properly.  However, before I download the file I need to access a website and the process of accessing it is what generates the file that I then download.

My code to access the website is Process.Start("url address").  This works, as well.  But what I do not know how to do is close the website after the file has been generated so at the end of the day I have several browser windows open to the same url.  I found some references to using javascript, but I don't know javascript so I am at a loss.  How can I close the browser window from my VB.net program?
0
T Hoecherl
Asked:
T Hoecherl
  • 2
  • 2
1 Solution
 
CodeCruiserCommented:
You can kill it afterwards

Process.Start returns a process object and you can call the Kill method on it

http://visualbasic.about.com/od/usingvbnet/a/prstrt.htm
0
 
T HoecherlDeveloperAuthor Commented:
OK.  I have this:

Dim myProcess As Process = Process.Start("url address")
        myProcess.Kill()

The browser opens to the correct url, but the myProcess.Kill() command generates this error:

NullReferenceException was unhandled
Object reference not set to an instance of an object.

0
 
CodeCruiserCommented:
You are starting it and then killing it straight away. Leave it to run and then kill it. IE takes time to start :-)
0
 
T HoecherlDeveloperAuthor Commented:
Thanks CodeCruiser.  I had to use this code to finally get it to work:

        Dim theProcesses() As Process = System.Diagnostics.Process.GetProcessesByName("Iexplore")
        For Each currentProcess As Process In theProcesses
             If currentProcess.MainWindowTitle.Equals("text in url") Then
                currentProcess.Kill()
            End If
        Next

but it does now do the job.  Thanks again.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now