T Hoecherl
asked on
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?
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?
ASKER
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.
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.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks CodeCruiser. I had to use this code to finally get it to work:
Dim theProcesses() As Process = System.Diagnostics.Process .GetProces sesByName( "Iexplore" )
For Each currentProcess As Process In theProcesses
If currentProcess.MainWindowT itle.Equal s("text in url") Then
currentProcess.Kill()
End If
Next
but it does now do the job. Thanks again.
Dim theProcesses() As Process = System.Diagnostics.Process
For Each currentProcess As Process In theProcesses
If currentProcess.MainWindowT
currentProcess.Kill()
End If
Next
but it does now do the job. Thanks again.
Process.Start returns a process object and you can call the Kill method on it
http://visualbasic.about.com/od/usingvbnet/a/prstrt.htm