A***** 的追踪清理器






1.71/5 (5投票s)
2007年4月12日
5分钟阅读

43909

1036
一篇关于清理用户计算机轨迹的文章
引言
本文档是关于跟踪清理的(清理可以用来获取关于您和您计算机的信息的文件/文件夹和注册表项),并介绍了如何使用注册表项、IO(删除文件/文件夹)来清理计算机上的基本跟踪信息。
使用代码
本文档中唯一重要的代码是以下部分,它们是我整个程序的主要组成部分。所有以下代码的作用是删除作为跟踪信息的文件/文件夹和注册表项。
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
此代码在程序启动时使用;以上所有代码的作用是告诉程序获取我们将在此程序中使用的重要文件夹的位置,并将它们放入标签中。程序从注册表项(使用 Windows XP [任何版本] 的每台计算机上都存在)获取所需文件夹的位置。然后,程序检查所需文件夹是否存在,如果存在,则程序将文件夹位置列在下面的标签中。
- Cookies 文件夹位置将放入 label2。
- History 文件夹位置将放入 label3。
- Recent 文件夹位置将放入 label4。
- Internet 缓存位置将放入 label5
- 最后一个比较特别(因为我不得不找到一种不同的方法来获取它的位置)——临时文件/文件夹。因为我找不到任何注册表项列出了它的位置。所以我不得不使用 `environment.username` 来获取用户的用户名。因此,临时文件夹的位置是C:\Documents and settings\Username\local settings\temp。然后程序检查 Temp 文件夹是否存在,如果存在,则临时文件/文件夹的位置将放入 label8。
需要删除的文件/文件夹
嗯,我不会在这里深入探讨。我将只解释代码在做什么。
所有代码的作用是检查我上面列出的文件夹是否存在,如果存在,则获取文件夹中的每个文件,并将其属性设置为正常。我这样做的原因是,如果一个文件是只读的,而我们尝试删除它怎么办?这可能会导致错误(因为有时只读文件无法删除)。
因此,将文件属性设置为正常更安全,因为它们可以被安全删除,除非文件正在使用中。如果它们正在使用中,它们就会被留在那里,因为它们无法被删除。至少,不是通过这个程序。
一旦文件属性被设置为正常,文件就可以被安全删除(除非正在使用中,此时它们会被保留)。一旦文件夹中的文件被删除,程序将尝试删除上面列出的不同重要文件(cookies、history 等)中的文件夹以及任何剩余的文件/文件夹。这是完成此操作的代码
If di.Exists = False Then
di.Create()
End If
如果目录不存在,此代码将创建目录。
并且
' 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)
此代码删除目录以及其中剩余的任何文件/文件夹(只要它们未在使用中)。
删除 Cookies 文件夹
此文件夹包含您计算机上的 cookies。Cookies 是小的文本文件,用于存储来自网站的信息,例如设置、密码(例如您在 CP 上的密码)。但它们可用于跟踪您的浏览习惯(例如您可能不想让别人知道的访问过的网站)。
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
删除 Recent 文件夹
此文件夹包含有关最近使用/执行的文件信息。
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
删除 History 文件夹
此文件夹中的文件包含特定日期您访问过的网页的信息。
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
删除 Internet 缓存文件夹
此文件夹包含您访问网页时下载的所有文件。其中的跟踪信息记录了您访问过的网页。
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
删除临时文件文件夹
此文件夹包含临时文件,这些文件会占用大量空间。其中也可能包含跟踪信息(Cookies、History 等)。
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
删除/创建注册表项/子项
现在我们来到最后一部分了,还在听吗?还在?好,没多少时间了。
下面的代码是不言自明的。它只是创建注册表项以确保其存在(因为如果注册表项不存在,会弹出错误,提示“注册表项不存在”之类的消息),然后删除注册表项。
删除输入的 URL
此注册表项包含有关您在网页浏览器中输入的网页的信息。
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 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 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
删除通用对话框的信息
此注册表项包含有关涉及 Windows 布局的某些设置的信息。但它们实际上并没有起到任何作用(它们不是必需的,删除它们是绝对安全的)。
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
删除流历史记录的信息
此注册表项包含作为二进制文件存储的注册表项。它们没有用,有时可能包含被视为跟踪信息的重要数据。
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
关注点
在创建此程序时,我面临的主要问题之一是正在使用的文件,例如 `index.dat` 文件。这些文件无法轻易删除(因为它们正在使用中),并且在尝试删除它们时偶尔会发生错误。为了解决这个问题,我添加了 `//On error goto err: err: '//DO NOTHING`,也就是错误捕获器。它可以捕获任何错误。或者,我也可以使用 `try` 和 `catch`,但我认为 `//on error goto err` 是一种我认为不那么麻烦的错误捕获方式。
此程序的更新
2007/05/13 - 使用 System.Web.Mail 类添加了与作者电子邮件通信的支持。
历史
- 2007/04/07 - 此程序第一个 Beta 版本。
- 2007/05/13 - 更新文章。此程序的第二个版本。欢迎任何改进/想法。