public class IEHere is the URL class:
{
public IEnumerable<URL> GetHistory()
{
UrlHistoryWrapperClass urlHistory;
UrlHistoryWrapperClass.STATURLEnumerator enumerator;
List<STATURL> list = new List<STATURL>();
urlHistory = new UrlHistoryWrapperClass();
enumerator = urlHistory.GetEnumerator();
enumerator.GetUrlHistory(list);
List<URL> URLs = new List<URL>();
foreach (STATURL url in list)
{
string browser = "-- Internet Explorer";
bool containsBoth = url.URL.Contains("file:///");
if (url.Title != "" && containsBoth == false){
Console.WriteLine(String.Format("{0} {1} {2}", url.Title, url.URL, browser));
Thread.Sleep(500);
}
}
return URLs;
}
}
public class URLHere is how you use this code:
{
string url;
string title;
string browser;
public URL(string url, string title, string browser)
{
this.url = url;
this.title = title;
this.browser = browser;
}
}
- Go to the Codeproject page, and download the demo project. You may have to sign up for a free account. Now, open up the "UrlHistoryLibrary" project in Visual Studio and then build it. You should now have a "UrlHistoryLibrary.dll" file in /bin/debug.
- Now, create a new console project in Visual Studio. I use the 2010 Pro version.
- Right click the "References" folder, in the Solution Explorer, and choose the option to "Add Reference". Now, select the "Browse" folder and navigate into your "UrlHistoryLibrary/Bin/Debug" folder and select "UrlHistoryLibrary.dll".
- Now, in your references, add
using UrlHistoryLibrary;
using System.Diagnostics;
using System.Threading; - Now, add the above IE class to your code. Right under that, outside of the IE class, add the URL class.
- Add a main class, or public static void Main(string[] args). Inside of that, include the following:
Process[] process_IE = Process.GetProcessesByName("iexplore");
if (process_IE.Length == 0)
{
IE ie = new IE();
ie.GetHistory();
}
else
Console.WriteLine("Sorry, IE is open. Please close IE and try again."); - Now, when you run your console program, you should get a list of History visited, in the format of Title, Url, Broswer.
A few notes:
- I have modified this a bit from the original code. I have made it so that the results will not display results with "file:///" in the url. It will also not display any empty titles.
- In the main function, I have added a check that will tell you if you have IE open, when you try to run. If so, it will give you an error message.
- I have added a 5 second delay between each URL.
Here is the complete tested source code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Threading;
using UrlHistoryLibrary;
namespace BlogTestIE
{
class Program
{
static void Main(string[] args)
{
Process[] process_IE = Process.GetProcessesByName("iexplore");
if (process_IE.Length == 0)
{
IE ie = new IE();
ie.GetHistory();
}
else
Console.WriteLine("Sorry, IE is open. Please close IE and try again.");
}
}
public class IE
{
public IEnumerableGetHistory()
{
UrlHistoryWrapperClass urlHistory;
UrlHistoryWrapperClass.STATURLEnumerator enumerator;
Listlist = new List ();
urlHistory = new UrlHistoryWrapperClass();
enumerator = urlHistory.GetEnumerator();
enumerator.GetUrlHistory(list);
ListURLs = new List ();
foreach (STATURL url in list)
{
string browser = "-- Internet Explorer";
bool containsBoth = url.URL.Contains("file:///");
if (url.Title != "" && containsBoth == false)
{
Console.WriteLine(String.Format("{0} {1} {2}", url.Title, url.URL, browser));
Thread.Sleep(500);
}
}
return URLs;
}
}
public class URL
{
string url;
string title;
string browser;
public URL(string url, string title, string browser)
{
this.url = url;
this.title = title;
this.browser = browser;
}
}
}