Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to clean up internet explorer cookies programmatically?

How to clean up internet explorer cookies programmatically?

Is there some windows API function to do it?

like image 538
Daniel Silveira Avatar asked Feb 04 '09 17:02

Daniel Silveira


2 Answers

Actually, I got it!

In Windows API you have a function to create cookies called InternetSetCookie, and you use it like this:

InternetSetCookie("http://teste.com", NULL, "name = value; expires = Sat,01-Jan-2020 00:00:00 GMT");

But, if you want to delete the cookie instead of creating it, you just have to set the expiration field somewhere in the past, like this:

InternetSetCookie("http://teste.com", NULL, "name = value; expires = Sat,01-Jan-2000 00:00:00 GMT");

More info about it in Managing Cookies.

like image 166
Daniel Silveira Avatar answered Oct 12 '22 11:10

Daniel Silveira


Couldn't you just search C:\Documents and Settings\user\Local Settings\Temporary Internet Files for files with 'cookie' in the filename?

Here's the Win32 call to get the folder:

BOOL SHGetSpecialFolderPath(
  HWND hwndOwner,
  LPTSTR lpszPath,
  int nFolder,
  BOOL fCreate 
);

Pass CSIDL_COOKIES as the nFolder argument.

Check this link out A Cleanup API for Windows.

You can delete cached cookies via the FindFirstUrlCacheEntry,FindNextUrlCacheEntry and DeleteUrlCacheEntry functions. You can pass 'cookie:' as the first argument (LPCTSTR lpszUrlSearchPattern) to FindFirstUrlCacheEntry.

like image 20
Phaedrus Avatar answered Oct 12 '22 11:10

Phaedrus