We help IT Professionals succeed at work.

How to Programmatically Delete a Cookie?

magenta
magenta asked
on
I am writing a program that needs to delete a specific cookie in the IE cookie cache. How do I do that, since cookies don't seem to be stored as files on the user's hard drive? I don't want to delete all cookies nor do I want to ask the end-user to do it. Any ideas or suggestions?

Thanks,
Frank
Comment
Watch Question

Commented:
>>since cookies don't seem to be stored as files on the user's hard drive?

Whatever gave you that idea?  Cookies for IE are stored in:

C:\WINDOWS\Cookies

for Win9x machines and:

C:\Documents and Settings\<user_folder>\Cookies

on Win2000.  It's also similar to that on NT4 but I don't have a machine handy to check right now.

Author

Commented:
I was looking at the folder shown by "View Files" throug Internet Options, which sends you to "c:\documents and settings\<user>\Local Settings\Temporary Internet Files" which doesn't correspond to any directory on disk. I guess IE is trying to hide where it really stores cookies?

Lemme give it a whack then at deleting files in this directory.

Thanks,
Frank
jkr
CERTIFIED EXPERT
Top Expert 2012

Commented:
Use 'InternetGetCookie()' to retrieve a cookie name for a certain URL and the 'InternetSetCookie()' with that name to set a NULL data pointer. See http://msdn.microsoft.com/library/default.asp?url=/workshop/networking/wininet/overview/cookie.asp
CERTIFIED EXPERT

Commented:
use the USERPROFILE environment variable and then from there look in the tempory internet files diredctory. here you will find the cookies, simply look through and find the name of the cookie you want to delete and put that in your code,

sprintf(path,"%s\\tempory internet files\\cookie_name@domainetchcygchghgh",your_pointer_to_the_env_var);
unlink(path);