|
-
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.
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
|