5

Using WinINet InternetGetCookie and InternetSetCookie functions, it's pretty straightforward to get and set cookie inside the application which makes a web request through WinINet.

However, I could not so far find a way to clear cookie.

Calling InternetSetCookie with blank data (either L"" or NULL) does not help (tried both with and without specifying the cookie name).

Tried FindFirst/NextUrlCacheGroup, DeleteUrlCacheGroup, and also FindFirst/NextUrlCacheEntry, DeleteUrlCacheEntry combinations. Still no luck.

Any ideas?

AllOutOfSalt
  • 1,516
  • 3
  • 27
  • 46
Kei
  • 1,596
  • 1
  • 16
  • 25

3 Answers3

7

Kei,

I had the same problem and a colleague of mine just helped me solve it. You need to call:

InternetSetOption(0, 42, NULL, 0);

The answer is taken from here.

This did the trick for my app and I hope it will work for you also.

Edit:
The "42" value in the function call stands for the "INTERNET_OPTION_END_BROWSER_SESSION" flag, which "Flushes entries not in use from the password cache on the hard disk drive. Also resets the cache time used when the synchronization mode is once-per-session. No buffer is required for this option. This is used by InternetSetOption." ( http://msdn.microsoft.com/en-us/library/aa385328%28v=vs.85%29.aspx )

Abdul Rahman
  • 2,097
  • 4
  • 28
  • 36
vladges
  • 71
  • 1
  • 4
1

This is a pretty old post, but I thought I'd add in my findings since I'm running into a similar issue - to clear a cookie, you need to set it's expiration date to a date in the past. This works for session cookies too:

InternetSetCookie("http://someurl.com", "mycookie" "somevalue;expires=Mon, 01 Jan 0001 00:00:00 GMT");

Mark
  • 346
  • 1
  • 2
  • 10
0

Click on the "Exclude..." button on the "Internet Properties" dialog box (General tab).

Internet properties / General tab

Select only the checkbox "Cookies and site data". Use the API Monitor (http://www.rohitab.com/apimonitor) to monitor the dialog box "Delete browse history"

Delete browser History

See what is done and execute the same thing using the Windows API functions presented. I found the solution that way