locked
Translate script for VB RRS feed

  • Question

  • Hello.  I have been trying to find a script which will allow me to delete Google Chromes History.  I found one that works as a batch file but Visual Studio doesn't let me execute it.  Can somebody please configure the following script for me so that I can use it in VB.. Thank you.

    set ChromeDataDir=C:\Users\%USERNAME%\AppData\Local\Google\Chrome\User Data\Default

    set ChromeCache=%ChromeDataDir%\Cache>nul 2>&1 

    del /q /s /f "%ChromeCache%\*.*">nul 2>&1   

    del /q /f "%ChromeDataDir%\*Cookies*.*">nul 2>&1   

    del /q /f "%ChromeDataDir%\*History*.*">nul 2>&1   

     

    set ChromeDataDir=C:\Users\%USERNAME%\Local Settings\Application Data\Google\Chrome\User Data\Default

    set ChromeCache=%ChromeDataDir%\Cache>nul 2>&1

    del /q /s /f "%ChromeCache%\*.*">nul 2>&1  

    del /q /f "%ChromeDataDir%\*Cookies*.*">nul 2>&1   

    del /q /f "%ChromeDataDir%\*History*.*">nul 2>&1

    • Moved by Amanda Zhu Wednesday, January 1, 2014 1:55 AM better forum
    Tuesday, December 31, 2013 1:16 PM

Answers

  • Hi,

    Welcome to MSDN.

    >> I found one that works as a batch file but Visual Studio doesn't let me execute it. 

    That batch file doesn't need to be opened with Visual Studio, you could execute that file by right clicking on that file, then choose "Run as Adminstrator".

    Or we could code as this way to run that batch file:

    Dim pi As New ProcessStartInfo("Path TO Batch File")
    Dim proc As Process = Process.Start(pi)

    In addition, that dos command lines just delete files by specific directory or files which contains specific words in file names. i.e :

    1. We could treat ChromeDataDir,ChromeCache,ChromeDataDir as variables which are String.

    The difference between "del /q /s /f" and "del /q /f" is:

     "del /q /s /f" will delete all files include these ones in the sub directories.

            For Each foundFile As String In My.Computer.FileSystem.GetFiles("e:\sql\test", _
                  FileIO.SearchOption.SearchAllSubDirectories, "*.*")
                File.Delete(foundFile)
            Next


     "del /q /f" will just delete all files in current directory.

            For Each foundFile As String In My.Computer.FileSystem.GetFiles("e:\sql\test", _
                   FileIO.SearchOption.SearchTopLevelOnly, "*Cookies*.*")
                File.Delete(foundFile)
            Next


    2. We could code as this way to get value of %USERNAME%:

            Dim winCur = System.Security.Principal.WindowsIdentity.GetCurrent()
            Dim _UserName = winCur.Name.Substring(winCur.Name.IndexOf("\") + 1)

    In addition, these forum is not to write any program for anybody, so I will not show every line translated, but we will share which way we will use to get that work.

    Thanks for your understanding.

    Regards.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    • Marked as answer by Carl Cai Monday, January 6, 2014 4:50 AM
    Wednesday, January 1, 2014 7:08 AM
  • Hello.  I have been trying to find a script which will allow me to delete Google Chromes History.  I found one that works as a batch file but Visual Studio doesn't let me execute it.  Can somebody please configure the following script for me so that I can use it in VB.. Thank you.

    set ChromeDataDir=C:\Users\%USERNAME%\AppData\Local\Google\Chrome\User Data\Default

    set ChromeCache=%ChromeDataDir%\Cache>nul 2>&1 

    del /q /s /f "%ChromeCache%\*.*">nul 2>&1   

    del /q /f "%ChromeDataDir%\*Cookies*.*">nul 2>&1   

    del /q /f "%ChromeDataDir%\*History*.*">nul 2>&1   

     

    set ChromeDataDir=C:\Users\%USERNAME%\Local Settings\Application Data\Google\Chrome\User Data\Default

    set ChromeCache=%ChromeDataDir%\Cache>nul 2>&1

    del /q /s /f "%ChromeCache%\*.*">nul 2>&1  

    del /q /f "%ChromeDataDir%\*Cookies*.*">nul 2>&1   

    del /q /f "%ChromeDataDir%\*History*.*">nul 2>&1

    I figure with the information below you can maybe configure your script to VB.Net on your own.

    I'm going to assume that you know which file to delete. I see the file in the below code is only 6 kb in length after it gets deleted and Chrome runs again. But perhaps that is because I have not used chrome enough and maybe the file Cookies-Journal needs to be deleted also or something.

    Option Strict On
    
    Public Class Form1
    
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            Me.CenterToScreen()
            If My.Computer.FileSystem.DirectoryExists("C:\Users\John\AppData\Local\Google\Chrome\User Data\Default") Then
                If My.Computer.FileSystem.FileExists("C:\Users\John\AppData\Local\Google\Chrome\User Data\Default\Cookies") Then
                    My.Computer.FileSystem.DeleteFile(("C:\Users\John\AppData\Local\Google\Chrome\User Data\Default\Cookies"))
                End If
            End If
        End Sub
    
    End Class

    This is Windows Explorer' in the image below, showing the files in that folder after the delete. Note that Windows Explorer shows another Cookies file that perhaps should be deleted also. Which is another file without an extension according to Windows Eplorer and the files properties. I see that Chrome recreates the file "Cookies" when the Chrome app runs but perhaps the file "Cookies-Journal" may need to be deleted also as maybe when the "Cookies" file, when Chrome runs again" is recreated from whatever the "Cookies-Journal" contains when Chrome runs. I haven't bothered to research all that.


    Please BEWARE that I have NO EXPERIENCE and NO EXPERTISE and probably onset of DEMENTIA which may affect my answers! Also, I've been told by an expert, that when you post an image it clutters up the thread and mysteriously, over time, the link to the image will somehow become "unstable" or something to that effect. :) I can only surmise that is due to Global Warming of the threads.






    • Edited by Mr. Monkeyboy Wednesday, January 1, 2014 8:56 AM 5555
    • Proposed as answer by IronRazerz Wednesday, January 1, 2014 10:14 AM
    • Marked as answer by Carl Cai Monday, January 6, 2014 4:50 AM
    Wednesday, January 1, 2014 8:30 AM
  • Hi,

     From the looks of it you want to clear the cache, history, and cookies. If so then according to THIS site that shows how to do this for all the common web browsers says you can delete the directory and that Chrome will create the directory anew. However, if you only want to clear the history then i read somewhere that the history is located in 4 different files that all have the word "History" in them. I don`t know if that is true because i don`t use chrome and can`t check. Below is what i was reading about the files for the history.

    The history is contained in four different files that all contain the word "History" and must be deleted in order to clear all of chrome's history. They look something like "History Index 2011-00-journal", "History Index 2011-00", "History", "History-journal". It's best to loop through each file in the directory, non-recursively, and filter for "History".


    EDIT : I wanted to add that if you try deleting the whole directory you should make a copy of it or back it up somehow first just in case they are wrong.

    • Proposed as answer by Mr. Monkeyboy Wednesday, January 1, 2014 9:55 AM
    • Edited by IronRazerz Wednesday, January 1, 2014 10:16 AM
    • Marked as answer by Carl Cai Monday, January 6, 2014 4:50 AM
    Wednesday, January 1, 2014 9:23 AM
  • Here is a way to properly get those paths to the Cache, Cookies, and History. You can do the dirty work of deleting them.

    Option Strict On
    Imports System.IO
    Module Module1
    
        Sub Main()
            Dim ChromeDir As String = Path.Combine(Environment.GetFolderPath _
                                                   (Environment.SpecialFolder.LocalApplicationData), _
                                                   "Google\Chrome\User Data\Default")
            Dim ChromeCache As String = Path.Combine(ChromeDir, "Cache")
            Dim ChromeCookies As String = Path.Combine(ChromeDir, "Cookies")
            Dim ChromeHistory As String = Path.Combine(ChromeDir, "History")
    
    
            Console.WriteLine("ChromeDir = " & ChromeDir)
            Console.WriteLine("ChromeCache = " & ChromeCache)
            Console.WriteLine("Cookies = " & ChromeCookies)
            Console.WriteLine("History = " & ChromeHistory)
    
            Console.ReadLine()
        End Sub
    End Module
    

    • Proposed as answer by IronRazerz Wednesday, January 1, 2014 2:18 PM
    • Marked as answer by Carl Cai Monday, January 6, 2014 4:50 AM
    Wednesday, January 1, 2014 2:01 PM
  •  I forgot to mention that somewhere i was also reading that the browser needed to be closed when you delete everything or it won`t work. As i said above though, i don`t know because i don`t use Chrome and can`t test it.   :)
    • Proposed as answer by Mr. Monkeyboy Wednesday, January 1, 2014 2:30 PM
    • Marked as answer by Carl Cai Monday, January 6, 2014 4:51 AM
    Wednesday, January 1, 2014 2:24 PM
  • Thanks for the replies everyone.  I ended up solving my problem by using the following code. 

    Shell("taskkill /F /IM chrome.exe)

    System.Threading.Thread.Sleep(5000)

    IfSystem.IO.File.Exists(CStr(Environ("USERPROFILE") & "\AppData\Local\Google\Chrome\User Data\Default\History")) = TrueThen

    Kill(CStr(Environ("USERPROFILE") & "\AppData\Local\Google\Chrome\User Data\Default\History"))

    End If

    • Marked as answer by Carl Cai Monday, January 6, 2014 4:47 AM
    Thursday, January 2, 2014 1:46 AM

All replies

  • Hi,

    I am moving this thread to Visual Basic forum for better response.

    Best regards,


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Wednesday, January 1, 2014 1:56 AM
  • Hi,

    Welcome to MSDN.

    >> I found one that works as a batch file but Visual Studio doesn't let me execute it. 

    That batch file doesn't need to be opened with Visual Studio, you could execute that file by right clicking on that file, then choose "Run as Adminstrator".

    Or we could code as this way to run that batch file:

    Dim pi As New ProcessStartInfo("Path TO Batch File")
    Dim proc As Process = Process.Start(pi)

    In addition, that dos command lines just delete files by specific directory or files which contains specific words in file names. i.e :

    1. We could treat ChromeDataDir,ChromeCache,ChromeDataDir as variables which are String.

    The difference between "del /q /s /f" and "del /q /f" is:

     "del /q /s /f" will delete all files include these ones in the sub directories.

            For Each foundFile As String In My.Computer.FileSystem.GetFiles("e:\sql\test", _
                  FileIO.SearchOption.SearchAllSubDirectories, "*.*")
                File.Delete(foundFile)
            Next


     "del /q /f" will just delete all files in current directory.

            For Each foundFile As String In My.Computer.FileSystem.GetFiles("e:\sql\test", _
                   FileIO.SearchOption.SearchTopLevelOnly, "*Cookies*.*")
                File.Delete(foundFile)
            Next


    2. We could code as this way to get value of %USERNAME%:

            Dim winCur = System.Security.Principal.WindowsIdentity.GetCurrent()
            Dim _UserName = winCur.Name.Substring(winCur.Name.IndexOf("\") + 1)

    In addition, these forum is not to write any program for anybody, so I will not show every line translated, but we will share which way we will use to get that work.

    Thanks for your understanding.

    Regards.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    • Marked as answer by Carl Cai Monday, January 6, 2014 4:50 AM
    Wednesday, January 1, 2014 7:08 AM
  • Hello.  I have been trying to find a script which will allow me to delete Google Chromes History.  I found one that works as a batch file but Visual Studio doesn't let me execute it.  Can somebody please configure the following script for me so that I can use it in VB.. Thank you.

    set ChromeDataDir=C:\Users\%USERNAME%\AppData\Local\Google\Chrome\User Data\Default

    set ChromeCache=%ChromeDataDir%\Cache>nul 2>&1 

    del /q /s /f "%ChromeCache%\*.*">nul 2>&1   

    del /q /f "%ChromeDataDir%\*Cookies*.*">nul 2>&1   

    del /q /f "%ChromeDataDir%\*History*.*">nul 2>&1   

     

    set ChromeDataDir=C:\Users\%USERNAME%\Local Settings\Application Data\Google\Chrome\User Data\Default

    set ChromeCache=%ChromeDataDir%\Cache>nul 2>&1

    del /q /s /f "%ChromeCache%\*.*">nul 2>&1  

    del /q /f "%ChromeDataDir%\*Cookies*.*">nul 2>&1   

    del /q /f "%ChromeDataDir%\*History*.*">nul 2>&1

    I figure with the information below you can maybe configure your script to VB.Net on your own.

    I'm going to assume that you know which file to delete. I see the file in the below code is only 6 kb in length after it gets deleted and Chrome runs again. But perhaps that is because I have not used chrome enough and maybe the file Cookies-Journal needs to be deleted also or something.

    Option Strict On
    
    Public Class Form1
    
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            Me.CenterToScreen()
            If My.Computer.FileSystem.DirectoryExists("C:\Users\John\AppData\Local\Google\Chrome\User Data\Default") Then
                If My.Computer.FileSystem.FileExists("C:\Users\John\AppData\Local\Google\Chrome\User Data\Default\Cookies") Then
                    My.Computer.FileSystem.DeleteFile(("C:\Users\John\AppData\Local\Google\Chrome\User Data\Default\Cookies"))
                End If
            End If
        End Sub
    
    End Class

    This is Windows Explorer' in the image below, showing the files in that folder after the delete. Note that Windows Explorer shows another Cookies file that perhaps should be deleted also. Which is another file without an extension according to Windows Eplorer and the files properties. I see that Chrome recreates the file "Cookies" when the Chrome app runs but perhaps the file "Cookies-Journal" may need to be deleted also as maybe when the "Cookies" file, when Chrome runs again" is recreated from whatever the "Cookies-Journal" contains when Chrome runs. I haven't bothered to research all that.


    Please BEWARE that I have NO EXPERIENCE and NO EXPERTISE and probably onset of DEMENTIA which may affect my answers! Also, I've been told by an expert, that when you post an image it clutters up the thread and mysteriously, over time, the link to the image will somehow become "unstable" or something to that effect. :) I can only surmise that is due to Global Warming of the threads.






    • Edited by Mr. Monkeyboy Wednesday, January 1, 2014 8:56 AM 5555
    • Proposed as answer by IronRazerz Wednesday, January 1, 2014 10:14 AM
    • Marked as answer by Carl Cai Monday, January 6, 2014 4:50 AM
    Wednesday, January 1, 2014 8:30 AM
  • Hi,

     From the looks of it you want to clear the cache, history, and cookies. If so then according to THIS site that shows how to do this for all the common web browsers says you can delete the directory and that Chrome will create the directory anew. However, if you only want to clear the history then i read somewhere that the history is located in 4 different files that all have the word "History" in them. I don`t know if that is true because i don`t use chrome and can`t check. Below is what i was reading about the files for the history.

    The history is contained in four different files that all contain the word "History" and must be deleted in order to clear all of chrome's history. They look something like "History Index 2011-00-journal", "History Index 2011-00", "History", "History-journal". It's best to loop through each file in the directory, non-recursively, and filter for "History".


    EDIT : I wanted to add that if you try deleting the whole directory you should make a copy of it or back it up somehow first just in case they are wrong.

    • Proposed as answer by Mr. Monkeyboy Wednesday, January 1, 2014 9:55 AM
    • Edited by IronRazerz Wednesday, January 1, 2014 10:16 AM
    • Marked as answer by Carl Cai Monday, January 6, 2014 4:50 AM
    Wednesday, January 1, 2014 9:23 AM
  • Haha Razerz, you certainly did more research than I bothered too.


    Please BEWARE that I have NO EXPERIENCE and NO EXPERTISE and probably onset of DEMENTIA which may affect my answers! Also, I've been told by an expert, that when you post an image it clutters up the thread and mysteriously, over time, the link to the image will somehow become "unstable" or something to that effect. :) I can only surmise that is due to Global Warming of the threads.

    Wednesday, January 1, 2014 9:57 AM
  • Haha Razerz, you certainly did more research than I bothered too.


     Not really. I did a quick search last night and must have typed in just the rite key words. I was just to tired to post it last night.
    Wednesday, January 1, 2014 10:13 AM
  • Here is a way to properly get those paths to the Cache, Cookies, and History. You can do the dirty work of deleting them.

    Option Strict On
    Imports System.IO
    Module Module1
    
        Sub Main()
            Dim ChromeDir As String = Path.Combine(Environment.GetFolderPath _
                                                   (Environment.SpecialFolder.LocalApplicationData), _
                                                   "Google\Chrome\User Data\Default")
            Dim ChromeCache As String = Path.Combine(ChromeDir, "Cache")
            Dim ChromeCookies As String = Path.Combine(ChromeDir, "Cookies")
            Dim ChromeHistory As String = Path.Combine(ChromeDir, "History")
    
    
            Console.WriteLine("ChromeDir = " & ChromeDir)
            Console.WriteLine("ChromeCache = " & ChromeCache)
            Console.WriteLine("Cookies = " & ChromeCookies)
            Console.WriteLine("History = " & ChromeHistory)
    
            Console.ReadLine()
        End Sub
    End Module
    

    • Proposed as answer by IronRazerz Wednesday, January 1, 2014 2:18 PM
    • Marked as answer by Carl Cai Monday, January 6, 2014 4:50 AM
    Wednesday, January 1, 2014 2:01 PM
  •  I forgot to mention that somewhere i was also reading that the browser needed to be closed when you delete everything or it won`t work. As i said above though, i don`t know because i don`t use Chrome and can`t test it.   :)
    • Proposed as answer by Mr. Monkeyboy Wednesday, January 1, 2014 2:30 PM
    • Marked as answer by Carl Cai Monday, January 6, 2014 4:51 AM
    Wednesday, January 1, 2014 2:24 PM
  • Hah! You're no doubt accurate though! Still watching Godzilla vs MegaGodzilla because there's obviously major scientific information I can glean from this. Or maybe I should just have another Jack and Coke!

    Please BEWARE that I have NO EXPERIENCE and NO EXPERTISE and probably onset of DEMENTIA which may affect my answers! Also, I've been told by an expert, that when you post an image it clutters up the thread and mysteriously, over time, the link to the image will somehow become "unstable" or something to that effect. :) I can only surmise that is due to Global Warming of the threads.



    • Edited by Mr. Monkeyboy Wednesday, January 1, 2014 2:34 PM 5555
    Wednesday, January 1, 2014 2:33 PM
  • Thanks for the replies everyone.  I ended up solving my problem by using the following code. 

    Shell("taskkill /F /IM chrome.exe)

    System.Threading.Thread.Sleep(5000)

    IfSystem.IO.File.Exists(CStr(Environ("USERPROFILE") & "\AppData\Local\Google\Chrome\User Data\Default\History")) = TrueThen

    Kill(CStr(Environ("USERPROFILE") & "\AppData\Local\Google\Chrome\User Data\Default\History"))

    End If

    • Marked as answer by Carl Cai Monday, January 6, 2014 4:47 AM
    Thursday, January 2, 2014 1:46 AM