-
Jul 18th, 2018, 09:35 PM
#1
Thread Starter
Member
How can I close a tab programmatically for Google Chrome?
I have a program that:
Reads the history of Chrome File then, compares that history to a text file, and if any websites from the history match the websites in the text file, a shows up which says the URL detected.
This is the code used in that program
Code:
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
Dim google As String = (Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + "\Google\Chrome\User Data\Default\History")
Dim fileName As String = DateTime.Now.Ticks.ToString
File.Copy(google, (Application.StartupPath + ("\" + fileName)))
Dim dt As New DataTable()
Using con As SQLiteConnection = New SQLiteConnection($"DataSource = {Application.StartupPath }\{fileName};Versio=3;New=False;Compress=True;")
Using cmd As New SQLiteCommand("select * from urls order by last_visit_time desc ", con)
con.Open()
Using dr As SQLiteDataReader = cmd.ExecuteReader()
dt.Load(dr)
End Using
End Using
End Using
Dim lstGoogleHistory As New List(Of String)
For Each row As DataRow In dt.Rows
lstGoogleHistory.Add(row("url").ToString)
Next
Dim WhiteListText As String = My.Computer.FileSystem.ReadAllText("websitelist.txt").ToString
Dim InWhiteList = From uri In lstGoogleHistory
Where uri.All(Function(x) WhiteListText.Contains(uri))
Select uri
For Each URL In InWhiteList
MessageBox.Show(URL)
Next
End Sub
It works great and does what I want it to do, however, I'm having trouble finding a solution for another little feature I want added, and that is, if a website is detected, the tab which the URL is located in will close.
I've had lots of trouble trying to find a solution for this, but I've found one which I don't think is a good way of doing it, and plus, it gives me the 'Access Denied' exception when used (yes my program is ran as administrator.)
Code:
SendKeys.Send("^w")
Is there a way to use Chrome's Task Manager to close the tab? And if so, how can this be done?
Or, could I send Control W to Chrome only?
Last edited by Modulus; Jul 18th, 2018 at 10:11 PM.
-
Jul 18th, 2018, 10:01 PM
#2
Re: How can I close a tab programmatically for Google Chrome?
There are ways of manipulating IE tabs, but I'm not aware of any with Chrome.
Try getting the tab window handle, and calling...
(find the structure with Spy++)
Dim WM_CLOSE As UInteger = &H10
PostMessage(handle, WM_CLOSE, 0, 0)
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Jul 18th, 2018, 10:11 PM
#3
Thread Starter
Member
Re: How can I close a tab programmatically for Google Chrome?
Ok, thanks.
Maybe there is a way to send Control W to Chrome only?
-
Jul 18th, 2018, 10:11 PM
#4
Thread Starter
Member
Re: How can I close a tab programmatically for Google Chrome?
Originally Posted by .paul.
There are ways of manipulating IE tabs, but I'm not aware of any with Chrome.
Try getting the tab window handle, and calling...
(find the structure with Spy++)
Dim WM_CLOSE As UInteger = &H10
PostMessage(handle, WM_CLOSE, 0, 0)
Ok, thanks.
Maybe there is a way to send Control W to Chrome only?
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|