?
Solved

Close Browser window with VB.net

Posted on 2011-10-24
4
Medium Priority
?
616 Views
Last Modified: 2012-05-12
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
Comment
Question by:thoecherl
  • 2
  • 2
4 Comments
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 37018924
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
 

Author Comment

by:thoecherl
ID: 37019153
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
 
LVL 83

Accepted Solution

by:
CodeCruiser earned 2000 total points
ID: 37020207
You are starting it and then killing it straight away. Leave it to run and then kill it. IE takes time to start :-)
0
 

Author Closing Comment

by:thoecherl
ID: 37021802
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

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
Suggested Courses

850 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