Click here to Skip to main content
15,881,248 members
Articles / Programming Languages / C#

Your Internet Explorer's Secrets

Rate me:
Please Sign up or sign in to vote.
4.87/5 (52 votes)
3 Mar 2009CPOL5 min read 71.7K   2K   119   19
See (and delete) what your Internet Explorer knows about you
Image 1

Introduction

This is a little program which helps you to see what your Internet Explorer stores about you. Additionally, it allows you to delete some of the files.

Background

Why this program? The Internet Explorer allows you to delete its cache, the browser's history and your cookies. So for what reason should you need this program?
Well, unfortunately the mentioned deleting is only half the truth. In fact, deleting your cache within the Internet Explorer means, that only your cache files will be removed. These files are in your users' directory under ..\Temporary Internet Files\Content.IE5 in subdirectories, which have such funny names like "09WJE130".
But there is another file, which contains all your visited internet links, storing them for a long, long time: "index.dat".
This file usually has a size of some MB. If you open it with a text editor and scroll down, you will detect hundreds of links in a readable form. And: this file will never be deleted by means of Internet Explorer.
So I've written this program to reveal, what your browser stores about you. And I want to give you the possibility to delete some of these annoying files.

Using the Code

As you can see in the image above, the main program contains a TabControl with six TabPages. Each of these TabPages allows you to administer a special part of the browser's files.

So let's begin with the TabPage Browser's URLs history, which appears after program start.
Background: If you would delete the browser's history in the Internet Explorer, all the previous visited links in the dropdown list of your browser would vanish. All these links are stored in the registry under "HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\TypedURLs" and after deletion, all the keys and values are gone. But sometimes, it's useful not to delete all of them or to store them in an own list to reuse them later (ok, there a favourites, I know...). Therefore, I've introduced two lists: the actual browser's history and a file, which stores my personal list.
The functionality within the TabPage above allows you to delete parts of your browser's history, store some links in your personal list or restore links from your personal list to the history. In the following you can see the function, which gets the TypedURLs from the registry and stores them in a listview.

C#
// registry branch for typed URLs (browser history)
public const string REG_URL = "SOFTWARE\\MICROSOFT\\INTERNET EXPLORER\\TYPEDURLS";
// registry branch for Internet Explorer
public const string REG_URL_SHORT = "SOFTWARE\\MICROSOFT\\INTERNET EXPLORER"; 
C#
/// <summary>
/// One element of the registry browser's history 
/// </summary>
public struct histlink
{
  // Entry name
  public string Entry;
  // URL
  public string URL;
}
C#
// Holds all values (URLs) from the registry browser's history
public static SortedList<int, histlink> historylinks = new SortedList<int, histlink>();
/// <summary>
/// Gets all the URL links from the registry and stores them in the 
/// SortedList historylinks.
/// </summary>
public void GetHistory()
{
  historylinks.Clear();
  using (RegistryKey tempKey = Registry.CurrentUser.OpenSubKey(REG_URL))
  {
    if (tempKey == null)
    {
      // try to set the registry entry
      using (RegistryKey tempKeyShort = 
      Registry.CurrentUser.OpenSubKey(REG_URL_SHORT, true))
      {
        if (tempKeyShort == null)
        {
          System.Windows.Forms.MessageBox.Show(
          "The registry entry for " + REG_URL_SHORT + " does not exist!",
          "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
          return;
        }
        else
        {
          tempKeyShort.CreateSubKey("TypedURLs", 
                                    RegistryKeyPermissionCheck.ReadWriteSubTree);
        }
      } // using
    } // if
  } // using
  // try it again
  using (RegistryKey tempKey = Registry.CurrentUser.OpenSubKey(REG_URL))
  {
    if (tempKey == null)
    {
      System.Windows.Forms.MessageBox.Show(
      "The registry entry for " + REG_URL + " does not exist!",
      "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
      return;
    } // if
    // get all keys
    string[] vals = tempKey.GetValueNames();
    int itemcounter = 0;
    foreach (string url in vals)
    {
      object keyValue = tempKey.GetValue(url);
      if (keyValue != null)
      {
        histlink hl = new histlink();
        string entry = keyValue.ToString();
        if (entry.Length != 0)
        {
          itemcounter++;
          hl.Entry = entry;
          hl.URL = url;
          historylinks.Add(itemcounter, hl);
        } // if
      } // if
    } // foreach
  } // using
} // GetHistory

The second TabPage Cache shows the browser's cache. On the one hand, there are the lots of cache files as mentioned above, e.g. 30,667 MB in 7991 cache files. You can delete them by pressing the button "Delete cache files". On the other hand, you can have some insight into "index.dat" by pressing "Show Index.dat". As this file is locked by many processes, it's not easy to delete it. So I've implemented a function "DeleteCacheIndexDat", which marks the file to be deleted on reboot (Button "Delete on reboot"). This function is a wrapper for MoveFileEx:

C#
// delete file on reboot
[System.Runtime.InteropServices.DllImport("kernel32.dll")]
private static extern bool MoveFileEx(string lpExistingFileName, 
                                      string lpNewFileName, int dwFlags);
const int MOVEFILE_DELAY_UNTIL_REBOOT = 0x00000004;
MoveFileEx(fileName, null, MOVEFILE_DELAY_UNTIL_REBOOT);

You can store some of the links in your personal list. To do so, select the links and press "Store selected". The lower listview on TabPage "Browser's URLs history", which holds your personal links, will be updated immediately.

The third TabPage History (Autofill) shows the browser's history, which is stored in a couple of "index.dat" files in your "Local Settings\History\History.IE5" directory and subdirectories. The links in these directories are responsible for the autofill mechanism in your browser's dropdown list. Some of these files (the older ones) can be deleted immediately, the others have to be deleted by means of "MoveFileEx". Use the buttons "Show history" and "Delete on reboot" to watch and delete the links.
You can also, as described above, store some links to your personal URL list.

The fourth TabPage Cookies shows your cookies. They are both stored in a file "index.dat" in your "Cookies" directory and as single .txt-files, each of them representing one cookie. Again, the "index.dat" can only be deleted on reboot, but the ".txt" cookie files can be deleted one by one. If you press "Show cookie files", the cookies and their third lines will be shown in the listview. The third line contains the cookie's URL. Use the button "Delete on reboot" to delete the cookie's index.dat file.
Again, you can overtake here some links to your personal URL list.

The fifth TabPage Recent list shows the list of the files you recently used. These are not specific browser links, but they are - sometimes - annoying too. You can get rid of them (or parts of them) by selecting and pressing "Delete selected". By the way: these links are on your "Recent" directory and have the suffix ".lnk".

Image 2

The sixth TabPage Delete all gives you the functionality to delete all that stuff at one go. You can reduce the overall deleting by unchecking some of the items. The deletion progress is shown by a progress bar.

Some Remarks on the Code

Not to have all the code in one large file, I've divided it up into several parts, meaning that every TabPage has its own source file. You can easily distinguish the parts, as they have the same name as the TabPages. All these source files are part of the class Main:

C#
public partial class Main : Form 

The program has been tested on Microsoft XP with Internet Explorer 6.0 and 7.0 and on Vista Home Premium with Internet Explorer 7.0. I've developed the solution with Visual Studio 2005, but it seems to work with Visual Studio 2008 as well.

Outlook - what to do:
It would be nice, if somebody could help me to show how a file, being locked by a couple of processes, can be deleted immediately. This should be done especially for the index.dat files to avoid deletion on reboot.

History

  • March 3rd, 2009 - First version

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Tester / Quality Assurance ifolor
Switzerland Switzerland
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
QuestionError Pin
Member 1018707625-Dec-13 23:55
Member 1018707625-Dec-13 23:55 
AnswerRe: Error -> Maybe solution Pin
Thomas Denzel26-Dec-13 7:36
Thomas Denzel26-Dec-13 7:36 
Dear member 10187076,

it´s surprising for me that people are still interested in this article.
I´ve written it with VS 2005 and it also worked with VS 2008 (a long time ago Wink | ;) )
Now, after having read your mail, I tried to convert the project to VS 2010 and I got
"Error generating XML documentation file 'c:\mabro.xml' ('Access denied')" on building the project.
The problem is that my OS (Vista) doesn't allow direct access to c:.
The solution is: Open the property page of the project (ManageBrowser), go to tab "Build" and section "Output". There you remove the check from the checkbox "XML documentation file:".
Years ago, I had OS XP and access to c: wasn't a problem.

I hope this will solve your problem. Unfortunately I've no VS 2012 at the moment to verify the solution for that development system too. If this my tip should not work, please don't hesitate to contact me again.

Greetings
Thomas
GeneralRe: Error -> Maybe solution Pin
Member 1018707626-Dec-13 7:49
Member 1018707626-Dec-13 7:49 
GeneralRe: Error -> Maybe solution Pin
Andy Crawford18-Oct-14 10:57
professionalAndy Crawford18-Oct-14 10:57 
QuestionGreat stuff! Pin
RedDk19-Jul-13 14:15
RedDk19-Jul-13 14:15 
GeneralMy vote of 5 Pin
lex_yacc15-Jul-10 5:37
lex_yacc15-Jul-10 5:37 
GeneralGreat !!!! Pin
keibel28-Feb-10 23:38
keibel28-Feb-10 23:38 
General5++ Pin
Jamal Alqabandi16-Mar-09 17:44
Jamal Alqabandi16-Mar-09 17:44 
GeneralGreat! Pin
Tiep Le9-Mar-09 15:56
Tiep Le9-Mar-09 15:56 
QuestionAnything similar for other browsers? Pin
Lee Humphries9-Mar-09 11:12
professionalLee Humphries9-Mar-09 11:12 
AnswerRe: Anything similar for other browsers? Pin
Thomas Denzel10-Mar-09 6:30
Thomas Denzel10-Mar-09 6:30 
GeneralRe: Anything similar for other browsers? Pin
Lee Humphries10-Mar-09 23:01
professionalLee Humphries10-Mar-09 23:01 
QuestionIs there the c++ version? Pin
xrzs5-Mar-09 3:09
xrzs5-Mar-09 3:09 
AnswerRe: Is there the c++ version? Pin
Thomas Denzel5-Mar-09 8:37
Thomas Denzel5-Mar-09 8:37 
GeneralRe: Is there the c++ version? Pin
xrzs5-Mar-09 21:16
xrzs5-Mar-09 21:16 
QuestionIs there the vb.net version? Pin
stevenyoung3-Mar-09 20:25
stevenyoung3-Mar-09 20:25 
AnswerRe: Is there the vb.net version? Pin
Paw Jershauge3-Mar-09 20:57
Paw Jershauge3-Mar-09 20:57 
GeneralRe: Is there the vb.net version? Pin
stevenyoung4-Mar-09 1:45
stevenyoung4-Mar-09 1:45 
AnswerRe: Is there the vb.net version? Pin
VDJ10-Mar-09 1:51
VDJ10-Mar-09 1:51 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.