Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

A*****'s tracker cleaner

0.00/5 (No votes)
16 May 2007 1  
An article on cleaning tracks from users computers

Screenshot - Programpic.jpg

Introduction

This article is on tracks cleaning, (cleaning files/folders and registry entries that can be used to get information about you and your computer) and introduces the use of Registry keys, IO(deleting files/folders), to clean basic tracks from your computer.

Using the code

The only code that is important in this article is the following which is the main part of my whole program. All the following code is used for is deleting the files/folders and registry keys that are tracks.

Private Sub Form1_Load(ByVal sender As System.Object, 
    ByVal e As System.EventArgs) Handles MyBase.Load
    Dim reg2 As Microsoft.Win32.RegistryKey = 
        Microsoft.Win32.Registry.CurrentUser.OpenSubKey(
            "Software\Microsoft\Windows\CurrentVersion\Explorer\Shell 
            Folders", True)
        '//Gets the location of the important directories and put them in a 

        '//label

        If System.IO.Directory.Exists(reg2.GetValue("Cookies", "")) Then
            Label2.Text = reg2.GetValue("Cookies", "")
        End If
        If System.IO.Directory.Exists(reg2.GetValue("History", "")) Then
            Label3.Text = reg2.GetValue("History", "")
        End If
        If System.IO.Directory.Exists(reg2.GetValue("Recent", "")) Then
            Label4.Text = reg2.GetValue("Recent", "")
        End If
        If System.IO.Directory.Exists(reg2.GetValue("Cache", "")) Then
            Label5.Text = reg2.GetValue("Cache", "")
        End If
        If System.IO.Directory.Exists("C:\Documents and Settings\" + 
           Environment.UserName + "\Local Settings\Temp") Then
           Label8.Text = "C:\Documents and Settings\" + Environment.UserName +
               "\Local Settings\Temp"
        End If
        End Sub

This code is used when we start the program; all the above code does is tell the program to get the location of the important folders that we will be using in this program and put them in a label. The program gets the folder location of the required folders from registry keys (that exist on every computer using Windows XP [any version]). Then the program checks whether the required folders exist, and if they do then the program puts the location of the folders in labels as listed below.

  1. The Cookies Folder location goes into label2.
  2. The History Folder location goes into label3.
  3. The Recent Folder location goes into label4.
  4. The Internet Cache location goes into label5
  5. And the last one which is special (because I had to find a different way to get its location) - the Temporary Files/Folders folder. Because no registry entry (I could find) lists its location. So I had to use environment.username to get the username of the user. So the location of the temporary folder is C:\Documents and settings\Username\local settings\temp. And then the program checks whether the Temp Folder exists, and if it does the location of the Temporary Files, folder goes into label8.

The Files/Folders that require deleting:

Well I'm not going to go into too much depth here. I will just explain what the code is accomplishing.

All the code does is check whether the folders that I listed above exist, and if they do, get each file in the folder, and set it to normal attributes. I did this because what happens if a file is read-only and we try and delete it? This could generate an error (because sometimes read-only files cannot be deleted).

Therefore, it was safer to just set the files to normal attributes because they can be safely deleted, unless the files are in-use. If they are in use, they are just left there because they cannot be deleted. At least, not by this program.

Then once the files attribute has been set to normal the files can be safely deleted (unless in-use, when they are left there). Once the files in the folder have been deleted, the program tries to delete the folder and any files/folders left in the different important files listed above (cookies, history etc.). This is the code that accomplishes this:

If di.Exists = False Then
    di.Create()
End If

This code creates the directory if it doesn't already exist.

And

' 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)

This code deletes the directory and any files/folders left in it (As long as they're not in-use).

Delete Cookies folder

This folder houses the cookies on your computer in it. Cookies are little text files that store information from websites such as settings, Passwords(such as your password for CP). But they can be used to track your surfing habits (such as websites visited that you may not want people to know about)

Public Sub DelCookies()
        Dim di As New DirectoryInfo(Environment.GetFolderPath(
            Environment.SpecialFolder.Cookies))
        On Error GoTo err
        ' 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.Cookies).ToString, FileAttributes.Normal)
        Dim Cookie1 As String '//Cookie1

        Dim Cookie2() As String '//Cookie2

        Cookie2 = IO.Directory.GetFiles(
            Environment.GetFolderPath(Environment.SpecialFolder.Cookies))
        For Each Cookie1 In Cookie2 '//Get all files that have .txt extension 

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

            If InStr(Cookie1, ".txt", CompareMethod.Text) Then
                IO.File.SetAttributes(Cookie1, FileAttributes.Normal)
                IO.File.Delete(Cookie1)
            End If
        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)
err:    '///IGNORE ERROR///

    End Sub

Delete Recent folder

This folder houses information on Recent files used/executed.

Public Sub Delrecent()
        Dim di As New DirectoryInfo(
            Environment.GetFolderPath(Environment.SpecialFolder.Recent))
        On Error GoTo err
        ' 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.Recent).ToString, FileAttributes.Normal)
        Dim recentk As String
        Dim Recentl() As String

        Recentl = IO.Directory.GetFiles(Environment.GetFolderPath(
            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)

err:    '///IGNORE ERROR///

    End Sub

Delete History folder

The files that are in this folder contain information on what webpages you visited on a particular date.

Public Sub Delhistory()
        Dim di As New DirectoryInfo(Environment.GetFolderPath(
            Environment.SpecialFolder.History))
        On Error GoTo err
        ' 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.History).ToString, FileAttributes.Normal)
        Dim history1 As String
        Dim history2() As String
        history2 = IO.Directory.GetFiles(Environment.GetFolderPath(
            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)

err:    '///IGNORE ERROR///

    End Sub 

Delete Internet Cache folder

This folder has all the files that are downloaded when you visit webpages in it. The tracks that are in here are, records of the webpages that you have visited.

Public Sub DelIECache()
        Dim di As New DirectoryInfo(Environment.GetFolderPath(
            Environment.SpecialFolder.InternetCache))
        On Error GoTo err
        ' 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)

err:    '///IGNORE ERROR///

    End Sub

Delete temporary files Folder

This folder has temporary files in it that can take up alot of space. It can also have tracks (Cookies,History etc...) stored in it.

Public Sub Deltemp()
        Dim di As New DirectoryInfo("C:\Documents and Settings\" + 
            Environment.UserName + "\Local Settings\Temp")
        On Error GoTo err
        ' 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("C:\Documents and Settings\" + 
            Environment.UserName + "\Local Settings\Temp", 
            FileAttributes.Normal)
        Dim temp1 As String
        Dim temp2() As String

        temp2 = IO.Directory.GetFiles("C:\Documents and Settings\" + 
            Environment.UserName + "\Local Settings\Temp")
        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)

err:    '///IGNORE ERROR///
    End Sub

Deleting/creating Registry keys/subkeys

Now we are on to the last bit, still with me? You are? Good; not long to go

The code below is self-explanatory. It is just creating the key to make sure it exists (because if the key doesn't exist an error comes up saying, something like, "Registry key didn't exist") and then deleting the Registry key.

Delete typed urls:

This registry key has information about Webpages that you have typed in your Web-browser.

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

Delete info on recent files run:

This registry key has information on Recent files that were opened on your computer.

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

Delete info on Recent docs:

This registry key has information in it about Recent documents that you have had open.

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

Delete info on Common dialog:

This registry key has information about certain settings that involve the layout of Windows. But they don't actually do anything(they are not required and are perfectly safe to delete).

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 SubM

Delete info on Stream history:

This registry key houses registry entries that are stored as Binaries. They have no use and can sometimes house important information in them that can be thought of as tracks.

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

Points of Interest

When creating this program one of the main problems that I faced were with files that were in-use, such as the index.dat files. These files cannot be easily deleted (because they are in-use) and when trying to delete these occasionally an error occured. To get around this I added '//On error goto err: err: '//DO NOTHING, aka an Error catcher. Which captures any errors. Alternatively I could have used try and catch but //on error goto err, is another way that I believe is less awkward, to use for error catching.

Updates to this program:

13/05/07 - Added in support for emailing author using the System.Web.Mail class.

History

  • 7/04/07 - First beta version of this program.
  • 13/05/07 - Updated article. Second version of this program. Any improvements/ideas are welcome.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here