Class clsClearHistories


Imports System.IO

Public Class clsClearHistories

    'https://www.codeproject.com/Articles/18380/A-s-tracker-cleaner

    Sub subClearALL()

        funWriteWordinColor("Thread (BEGIN): " & Threading.Thread.CurrentThread.ManagedThreadId.ToString & vbCrLf, ConsoleColor.Cyan)

        Delrecent()

        Delhistory()

        DelIECache()

        Deltemp()

        Deltypedurls()

        DelRecfiles()

        DelRecdocs()

        DelComD()

        DelStMru()

        DelOfficeLinks()

        funWriteWordinColor("Thread (END): " & Threading.Thread.CurrentThread.ManagedThreadId.ToString & vbCrLf, ConsoleColor.Cyan)

    End Sub

    Public Sub DelOfficeLinks()

        Dim reg4 As Microsoft.Win32.RegistryKey

        For x = 8 To 19

            Dim aLocations As String() = {"Reading Locations", "User MRU", "File MRU", "Reading Locations", "Place MRU"}

            Dim aProducts As String() = {"Excel", "Access", "Word", "PowerPoint", "MS Project", "OneNote", "Visio"}

            For Each sProduct In aProducts

                Try

                    reg4 = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("Software\Microsoft\Office\" & x & ".0\" & sProduct, True)

                    For Each sLocation In aLocations

                        reg4.CreateSubKey(sLocation) '//Typedurls-Url typed

                        reg4.DeleteSubKeyTree(sLocation) '//delete subkey and all subkeys

                    Next

                Catch

                End Try

            Next

            '         reg4 = Microsoft.Win32.Registry.

            '   CurrentUser.OpenSubKey("Software\Microsoft\Office\" & x & ".0\Word",

            '       True)

            '         reg4.CreateSubKey("Reading Locations") '//Typedurls-Url typed

            '         reg4.DeleteSubKeyTree("Reading Locations") '//delete subkey and all subkeys

            '         reg4 = Microsoft.Win32.Registry.

            '       CurrentUser.OpenSubKey("Software\Microsoft\Office\" & x & ".0\Access",

            '           True)

            '         reg4.CreateSubKey("File MRU") '//Typedurls-Url typed

            '         reg4.DeleteSubKeyTree("File MRU") '//delete subkey and all subkeys

            '         reg4 = Microsoft.Win32.Registry.

            '       CurrentUser.OpenSubKey("Software\Microsoft\Office\" & x & ".0\Access",

            '           True)

            '         reg4.CreateSubKey("Place MRU") '//Typedurls-Url typed

            '         reg4.DeleteSubKeyTree("Place MRU") '//delete subkey and all subkeys

            '         reg4 = Microsoft.Win32.Registry.

            '          CurrentUser.OpenSubKey("Software\Microsoft\Office\" & x & ".0\MS Project",

            '              True)

            '         reg4.CreateSubKey("File MRU") '//Typedurls-Url typed

            '         reg4.DeleteSubKeyTree("File MRU") '//delete subkey and all subkeys

            '         reg4 = Microsoft.Win32.Registry.

            '                CurrentUser.OpenSubKey("Software\Microsoft\Office\" & x & ".0\MS Project",

            '                    True)

            '         reg4.CreateSubKey("Place MRU") '//Typedurls-Url typed

            '         reg4.DeleteSubKeyTree("Place MRU") '//delete subkey and all subkeys

            '         reg4 = Microsoft.Win32.Registry.

            '                CurrentUser.OpenSubKey("Software\Microsoft\Office\" & x & ".0\OneNote",

            '                    True)

            '         reg4.CreateSubKey("User MRU") '//Typedurls-Url typed

            '         reg4.DeleteSubKeyTree("User MRU") '//delete subkey and all subkeys

            '         reg4 = Microsoft.Win32.Registry.

            'CurrentUser.OpenSubKey("Software\Microsoft\Office\" & x & ".0\PowerPoint",

            '    True)

            '         reg4.CreateSubKey("User MRU") '//Typedurls-Url typed

            '         reg4.DeleteSubKeyTree("User MRU") '//delete subkey and all subkeys

            '         reg4 = Microsoft.Win32.Registry.

            '         CurrentUser.OpenSubKey("Software\Microsoft\Office\" & x & ".0\PowerPoint",

            '             True)

            '         reg4.CreateSubKey("File MRU") '//Typedurls-Url typed

            '         reg4.DeleteSubKeyTree("File MRU") '//delete subkey and all subkeys

            '         reg4 = Microsoft.Win32.Registry.

            '                    CurrentUser.OpenSubKey("Software\Microsoft\Office\" & x & ".0\PowerPoint",

            '                        True)

            '         reg4.CreateSubKey("Place MRU") '//Typedurls-Url typed

            '         reg4.DeleteSubKeyTree("Place MRU") '//delete subkey and all subkeys

            '         reg4 = Microsoft.Win32.Registry.

            'CurrentUser.OpenSubKey("Software\Microsoft\Office\" & x & ".0\Visio",

            '    True)

            '         reg4.CreateSubKey("User MRU") '//Typedurls-Url typed

            '         reg4.DeleteSubKeyTree("User MRU") '//delete subkey and all subkeys

            '         reg4 = Microsoft.Win32.Registry.

            '         CurrentUser.OpenSubKey("Software\Microsoft\Office\" & x & ".0\Visio",

            '             True)

            '         reg4.CreateSubKey("File MRU") '//Typedurls-Url typed

            '         reg4.DeleteSubKeyTree("File MRU") '//delete subkey and all subkeys

            '         reg4 = Microsoft.Win32.Registry.

            '                    CurrentUser.OpenSubKey("Software\Microsoft\Office\" & x & ".0\Visio",

            '                        True)

            '         reg4.CreateSubKey("Place MRU") '//Typedurls-Url typed

            '         reg4.DeleteSubKeyTree("Place MRU") '//delete subkey and all subkeys

        Next

        '//in it

    End Sub

    Public Sub DelStMru()

        Dim reg5 As Microsoft.Win32.RegistryKey =

            Microsoft.Win32.Registry.CurrentUser.OpenSubKey(

                "Software\Microsoft\Windows\CurrentVersion\Explorer", True)

        reg5.CreateSubKey("StreamMRU")         '//StreamMru-Stream history.

        reg5.DeleteSubKeyTree("StreamMRU") '//delete subkey and all subkeys

        '//in it

    End Sub

    Public Sub DelComD()

        Dim reg5 As Microsoft.Win32.RegistryKey = Microsoft.Win32.Registry.

             CurrentUser.OpenSubKey("Software\Microsoft\Windows\CurrentVersion\Explorer", True)

        reg5.CreateSubKey("ComDlg32") '//Comdlg32-Common dialog

        reg5.DeleteSubKeyTree("ComDlg32") '//delete subkey and all subkeys in

        '//it

    End Sub

    Public Sub DelRecdocs()

        Dim reg5 As Microsoft.Win32.RegistryKey = Microsoft.Win32.Registry.

            CurrentUser.OpenSubKey("Software\Microsoft\Windows\CurrentVersion\Explorer", True)

        reg5.CreateSubKey("RecentDocs") '//Recentdocs-Recent documents opened

        reg5.DeleteSubKeyTree("RecentDocs") '//delete subkey and all subkeys

        '//in it

    End Sub

    Public Sub DelRecfiles()

        Dim reg5 As Microsoft.Win32.RegistryKey = Microsoft.Win32.Registry.

            CurrentUser.OpenSubKey("Software\Microsoft\Windows\CurrentVersion\Explorer", True)

        reg5.CreateSubKey("RunMRU") '//Runmru-Recent files run.

        reg5.DeleteSubKeyTree("RunMRU") '//delete subkey and all subkeys in

        '//it

    End Sub

    Public Sub Deltypedurls()

        Dim reg4 As Microsoft.Win32.RegistryKey = Microsoft.Win32.Registry.

            CurrentUser.OpenSubKey("Software\Microsoft\Internet Explorer",

                True)

        reg4.CreateSubKey("TypedURLs") '//Typedurls-Url typed

        reg4.DeleteSubKeyTree("TypedURLs") '//delete subkey and all subkeys

        '//in it

    End Sub

    Public Sub Deltemp()

        Try

            Dim di As New DirectoryInfo(Environment.ExpandEnvironmentVariables(Environment.GetEnvironmentVariable("TEMP")))

            ' Create the directory only if it does not already exist.

            If di.Exists = False Then

                di.Create()

            End If

            '//Set folder to normal attributes to allow easy deletion (and to get

            '//rid of any read-only attributes, which make it hard to delete the

            '//files/folder)

            System.IO.File.SetAttributes(Environment.ExpandEnvironmentVariables(Environment.GetEnvironmentVariable("TEMP").ToString),

            FileAttributes.Normal)

            Dim temp1 As String

            Dim temp2() As String

            temp2 = IO.Directory.GetFiles(Environment.ExpandEnvironmentVariables(Environment.GetEnvironmentVariable("TEMP").ToString))

            For Each temp1 In temp2 '//Get all files in Temp folder and then set

                '//their attribute to normal, and then delete them.

                IO.File.SetAttributes(temp1, FileAttributes.Normal)

                IO.File.Delete(temp1)

            Next

            ' The true indicates that if subdirectories

            ' or files are in this directory, they are to be deleted as well.

            ' Delete the directory.

            di.Delete(True)

        Catch

        End Try

    End Sub

    Public Sub DelIECache()

        Try

            Dim di As New DirectoryInfo(Environment.GetFolderPath(

            Environment.SpecialFolder.InternetCache))

            ' Create the directory only if it does not already exist.

            If di.Exists = False Then

                di.Create()

            End If

            '//Set folder to normal attributes to allow easy deletion (and to get

            '//rid of any read-only attributes, which make it hard to delete the

            '//files/folder)

            System.IO.File.SetAttributes(Environment.GetFolderPath(

            Environment.SpecialFolder.InternetCache).ToString,

            FileAttributes.Normal)

            Dim Cache1 As String

            Dim Cache2() As String

            Cache2 = IO.Directory.GetFiles(Environment.GetFolderPath(

            Environment.SpecialFolder.InternetCache))

            For Each Cache1 In Cache2 '//Get all files in Temporary internet

                '//files, folder and then set their attribute to normal, and then

                '//delete them.

                IO.File.SetAttributes(Cache1, FileAttributes.Normal)

                IO.File.Delete(Cache1)

            Next

            ' The true indicates that if subdirectories

            ' or files are in this directory, they are to be deleted as well.

            ' Delete the directory.

            di.Delete(True)

        Catch

        End Try

    End Sub

    Public Sub Delhistory()

        Try

            Dim di As New DirectoryInfo(Environment.ExpandEnvironmentVariables(

            Environment.SpecialFolder.History))

            ' Create the directory only if it does not already exist.

            If di.Exists = False Then

                di.Create()

            End If

            '//Set folder to normal attributes to allow easy deletion (and to get

            '//rid of any read-only attributes, which make it hard to delete the

            '//files/folder)

            System.IO.File.SetAttributes(Environment.ExpandEnvironmentVariables(

           Environment.SpecialFolder.History).ToString, FileAttributes.Normal)

            Dim history1 As String

            Dim history2() As String

            history2 = IO.Directory.GetFiles(Environment.ExpandEnvironmentVariables(

            Environment.SpecialFolder.History))

            For Each history1 In history2 '//Get all files in history folder and

                '//then set their attribute to normal, and then delete them.

                IO.File.SetAttributes(history1, FileAttributes.Temporary)

                IO.File.Delete(history1)

            Next

            ' The true indicates that if subdirectories

            ' or files are in this directory, they are to be deleted as well.

            ' Delete the directory.

            di.Delete(True)

        Catch

        End Try

    End Sub

    Public Sub Delrecent()

        Try

            Dim di As New DirectoryInfo(

            Environment.ExpandEnvironmentVariables(Environment.SpecialFolder.Recent))

            ' Create the directory only if it does not already exist.

            If di.Exists = False Then

                di.Create()

            End If

            '//Set folder to normal attributes to allow easy deletion (and to get

            '//rid of any read-only attributes, which make it hard to delete the

            '//files/folder)

            System.IO.File.SetAttributes(Environment.ExpandEnvironmentVariables(

            Environment.SpecialFolder.Recent).ToString, FileAttributes.Normal)

            Dim recentk As String

            Dim Recentl() As String

            Recentl = IO.Directory.GetFiles(Environment.ExpandEnvironmentVariables(

            Environment.SpecialFolder.Recent))

            For Each recentk In Recentl '//Get all files in recent folder and then

                '//set their attribute to normal, and then delete them.

                IO.File.SetAttributes(recentk, FileAttributes.Normal)

                IO.File.Delete(recentk)

            Next

            ' The true indicates that if subdirectories

            ' or files are in this directory, they are to be deleted as well.

            ' Delete the directory.

            di.Delete(True)

        Catch

        End Try

    End Sub

End Class