C # obtain IE browsing records for system applications and enter the web site in the IE Address Bar

Source: Internet
Author: User
Tags filetime


This article is a series of system application articles for the "Personal Computer History cleanup software" project.
Front"
C # clearing Cookies, temporary IE files, and history of System Applications"I have explained how to use rundll32.exe to run dll files to clear the IE cache. There are also many ways to delete these files on the Internet, but how can I obtain the historical website records recently viewed in IE and the URLs entered in the address bar of IE? This is what I need to explain in this article.

1. Environment. GetFolderPath method to obtain IE history

As mentioned above, the path of IE History in Windows is: "C: \ Users \ dell \ AppData \ Local \ Microsoft \ Windows \ History ",A historical record is a website address that has been visited recently. It is stored at the time and site, as shown in:

Then, we can use Environment. GetFolderPath (Environment. SpecialFolder. History) to obtain the IE History.

Private void button3_Click (object sender, EventArgs e) {// clear listBox listBox1.Items. clear (); // obtain the path of the Internet history file string dirPath = Environment. getFolderPath (Environment. specialFolder. history); listBox1.Items. add ("Internet history path:"); listBox1.Items. add (dirPath); // traverse all folders to display all files DirectoryInfo dir = new DirectoryInfo (dirPath); int num = 1; foreach (FileInfo file in dir. getFiles ("*. * ", SearchOption. allDirectories) {try {listBox1.Items. add ("(" + num + ")" + file); num ++;} catch (Exception msg) // Exception Handling {MessageBox. show (msg. message );}}}

Here, Environment. GetFolderPath (Environment. SpecialFolder. XXX) is used to retrieve the path of special folders in the system. Common examples include:
(1). History is used as the directory of the public repository for Internet History items
(2). The directory where Cookies are used as the public repository of Internet Cookies
(3) The directory where InternetCache is used as the public repository for Temporary Internet Files
(4). Recent contains the directory of the document recently used by the user
(5). MyPictures "My Pictures" folder
(6). MyDocuments "my computer" folder
(7). ProgramFiles "Program files" Directory
However, when you run the delete or retrieve operation, it usually has system files and many files cannot be accessed. in the deletion process, you will encounter "this file is being used by another process, so this process cannot access this file" or "the file access is denied" .and then rundll32.exe calls the Win32 API function ShellExecute () implemented. similarly, use it to obtain the obtained historical records, as shown in. obviously it is not the result I want, and a lot of Cookies can still be displayed after Cookies are cleared. guess it's from Google, or other browsers?


Ii. RegistryKey: Obtain the IE Address Bar URL in the RegistryKey Registry

Open the run (Ctrl + R) and enter "regedit" to open the Registry. Under "HKEY_CURRENT_USER \ Software \ Microsoft \ Internet Explorer \ TypedURLs", you can see the URL recently entered by IE browser in the address bar, as shown in:

Shows the corresponding IE browser:

The following code uses the RegistryKey registry top-level node and obtains files under this path to display the address bar URL of IE. Note that RegistryKey must reference the namespace using Microsoft. Win32.

////// Obtain the IE Address Bar and enter the URL /////////Private void button2_Click (object sender, EventArgs e) {// defines the Registry top-level node. Its namespace is using Microsoft. win32; RegistryKey historykey; // retrieves the current user's CurrentUser sub-item Software \ Microsoft \ Internet Explorer \ typedURLs historykey = Registry. currentUser. openSubKey ("Software \ Microsoft \ Internet Explorer \ typedURLs", true); if (historykey! = Null) {// obtain all retrieved values String [] names = historykey. getValueNames (); foreach (String str in names) {listBox1.Items. add (historykey. getValue (str ). toString () ;}} else {MessageBox. show (this, "No URL to delete in IE address bar", "prompt dialog box", MessageBoxButtons. OK, MessageBoxIcon. warning );}}

Shows the running result:

Iii. COM interface IUrlHistoryStg2 get IE browsing records

Here we mainly useWang Ji YuThe method described by the instructor is implemented through the COM interface provided by IE. Thank you for your article.
References:
Http://bbs.csdn.net/topics/290070046The Code is as follows:

Using System; using System. collections. generic; using System. componentModel; using System. data; using System. drawing; using System. linq; using System. text; using System. threading. tasks; using System. windows. forms; using System. runtime. interopServices; // namespace using System. reflection; // provides the loading type Pointer using Microsoft. win32; // RegistryKeynamespace GetIE {# region COM interface to obtain IE history records // custom IUrlHistory public struct STATURL {public static uint SIZEOF_STATURL = (uint) Marshal. sizeOf (typeof (STATURL); public uint cbSize; // webpage size [financialas (UnmanagedType. LPWStr)] // webpage Url public string pwcsUrl; [financialas (UnmanagedType. LPWStr)] // The webpage title public string pwcsTitle; public System. runtime. interopServices. comTypes. FILETIME ftLastVisited, // The last access time of the webpage ftLastUpdated, // The Last Update Time of the webpage ftExpires; public uint dwFlags;} // The ComImport attribute calls the com component [ComImport, guid ("3C374A42-BAE4-11CF-BF7D-00AA006946EE"), InterfaceType (ComInterfaceType. interfaceIsIUnknown)] interface IEnumSTATURL {[PreserveSig] // search the matching search mode of IE history and copy it to the specified uint Next (uint celt, out STATURL rgelt, out uint pceltFetched ); void Skip (uint celt); void Reset (); void Clone (out IEnumSTATURL ppenum); void SetFilter ([delealas (UnmanagedType. LPWStr)] string poszFilter, uint dwFlags);} [ComImport, Guid ("AFA0DC11-C313-11d0-831A-00C04FD5AE38"), InterfaceType (ComInterfaceType. interfaceIsIUnknown)] interface IUrlHistoryStg2 {# region IUrlHistoryStg methods void AddUrl ([financialas (UnmanagedType. LPWStr)] string pocsUrl, [financialas (UnmanagedType. LPWStr)] string pocsTitle, uint dwFlags); void DeleteUrl ([financialas (UnmanagedType. LPWStr)] string pocsUrl, uint dwFlags); void QueryUrl ([financialas (UnmanagedType. LPWStr)] string pocsUrl, uint dwFlags, ref STATURL lpSTATURL); void BindToObject ([financialas (UnmanagedType. LPWStr)] string pocsUrl, ref Guid riid, [financialas (UnmanagedType. IUnknown)] out object ppvOut); IEnumSTATURL EnumUrls (); # endregion void AddUrlAndNotify ([financialas (UnmanagedType. LPWStr)] string pocsUrl, [financialas (UnmanagedType. LPWStr)] string pocsTitle, uint dwFlags, [financialas (UnmanagedType. bool)] bool fWriteHistory, [financialas (UnmanagedType. IUnknown)] object/* IOleCommandTarget */poctNotify, [financialas (UnmanagedType. IUnknown)] object punkISFolder); void ClearHistory (); // Clear history} [ComImport, Guid ("3C374A40-BAE4-11CF-BF7D-00AA006946EE")] class UrlHistory /*: IUrlHistoryStg [2] */{}# endregion // call the IUrHistory method of the COM interface to implement public partial class Form1: Form {public Form1 () {InitializeComponent ();} private void button#click (object sender, EventArgs e) {response = (response) new UrlHistory (); IEnumSTATURL vEnumSTATURL = Response (); STATURL vSTATURL; uint vFectched; while (vEnumSTATURL. next (1, out vSTATURL, out vFectched) = 0) {richTextBox1.AppendText (string. format ("{0} \ r \ n {1} \ r \ n", vSTATURL. pwcsTitle, vSTATURL. pwcsUrl ));}}}}

The running result after my processing is shown in:

This article also provides an article that uses another method to call the API function of IE.
Http://blog.sina.com.cn/s/blog_589d32f5010007xf.html
However, I also encountered a problem: Its ftLastVisited (The last time the user visited this page) stores The last access time of the webpage, you want to obtain the first 100 of today's access or sort the output at this time. however, the total output error occurred when obtaining the time and converting FILETIME to SYSTEMTIME or time_t failed. hope to solve the problem in the future.
In the end, this article focuses on explaining your own things. If you encounter similar problems, it may be helpful to you. at the same time, if you encounter errors or deficiencies in the article, please haihan! The most important thing is to thank the bloggers mentioned above. I hope they can solve problems such as getting time and so on. Please respect the fruits of the author's work and do not spray it !!!
(By: Eastmount 2014-4-3 night half past two original CSDNhttp: // blog.csdn.net/eastmount /)


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.