Close Browser window with

Posted on 2011-10-24
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 program?
Question by:thoecherl
    LVL 83

    Expert Comment

    You can kill it afterwards

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

    Author Comment

    OK.  I have this:

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

    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.

    LVL 83

    Accepted Solution

    You are starting it and then killing it straight away. Leave it to run and then kill it. IE takes time to start :-)

    Author Closing Comment

    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
                End If

    but it does now do the job.  Thanks again.

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
    If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
    how to add IIS SMTP to handle application/Scanner relays into office 365.
    Sending a Secure fax is easy with eFax Corporate ( First, Just open a new email message.  In the To field, type your recipient's fax number You can even send a secure international fax — just include t…

    731 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

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now