This is going to be a small privacy tutorial on how to clear cache, cookies and history in all five major browsers - Internet Explorer, Chrome, Firefox, Opera and Safari. The techniques here work only on Windows operating system but it's not hard to transfer the techniques to other systems. The tutorial comes with Windows batch scripts for each browser. It also documents how to erase the nasty flash cookies that are browser independent.

I wrote these batch scripts for the Browserling startup that I am doing together with James Halliday. The problem was that the browsers had to be reset between consequent uses. The easiest way to solve it was to run a batch cleanup script after each browser.

Google Chrome

Chrome stores history, cookies, cache and bookmarks in various databases and directories in the per-user application data directory at C:\Users\<username>\AppData\Local\Google\Chrome\User Data. The easiest way to get rid of all this data is just to erase everything there. Chrome creates this directory anew if it finds it missing.

This simple batch script first deletes all files in %ChromeDir% directory via del command and then deletes the directory itself via rd command. The /q flag makes the del command quiet, the /s makes it delete files from all subdirectories, and /f forces it to delete read-only files, too. The /s flag to rd makes it delete all subdirectories and /q makes rd quiet.

Mozilla Firefox

Firefox stores cookies, cache and history in two places. The first is per-user appdata directory C:\Users\<username>\AppData\Local\Mozilla\Firefox\Profiles and the second place is roaming profile data directory C:\Users\<username>\AppData\Roaming\Mozilla\Firefox\Profiles. To get rid of all the private data, delete the local data directory and delete all sqlite databases from the roaming data directory.

The for command loops over all profile directories and deletes all the sqlite databases. You can also delete the whole roaming data directory but I didn't because Firefox stores extensions there, and there are several I use for Browserling.

Opera

Opera also stores cookies, cache and history in two different locations - the user's application data directory C:\Users\<username>\AppData\Local\Opera\Opera and the user's roaming data directory C:\Users\<username>\AppData\Roaming\Opera\Opera. Just get rid of both directories and you're safe.

Kevin, you completely misunderstood what this code is for. It's for the public (free) browserling instances. It does exactly what it's supposed to - it clears the cache, cookies, and history after you, so that the next user did not know who you were. You don't really want YOUR cache be seen by the next user!

For the private, paid accounts, of course, we will not be wiping cache, cookies or history. You'll have your own private account and you will be the only one who accesses it.

My bad, this is a formal apology. I even read the code 2x but inexplicably did not check the context. Apologies, and seriously hoping the startup goes well. High hopes and all that, and of course you are right about the clean wiping of a remote instance.

It's just that many web apps ask you to wipe your cache for many reasons... but this does not excuse my lack of due diligence whatsoever.

@Kevin
Dude. You should not be implementing and executing code without understanding it. It's very clear what the code is doing. If you are not a coder, then again--you have no business messing around with it.

This is a bad idea. These scripts at least for firefox are deleting way more than just cookies. This includes all the user preferences, history, etc. On top of that there are better ways to do this build into the browser. At the very least you should be using sqlite to just drop the rows in cookies.sqlite.

Any discussion about browser cookies should also include flash cookies, which can only be done by visiting Adobe's site - http://www.macromedia.com/support/documentation/en/flashplayer/help/settings_manager07.html

Stop the C:\Users\%USERNAME%\AppData\Local nonsense, you cannot assume anyone has the same directory structure. Localized (non-English) Windows versions, different Windows versions (care to see your code blow up on XP?), all of these make your code unportable.

If you change every C:\Users\%USERNAME%\AppData\Local instance to %LOCALAPPDATA% then your code will be portable and my eyes will stop bleeding! For instances of C:\Users\%USERNAME%\AppData\Roaming you can use %APPDATA% instead. Typing in SET at the command prompt is your friend...

About the actual content, THANKS! It's always good to know how to erase abosolutely everything from your browsing history.

He can assume because it's his virtual machine, so he controls the OS and the folder location expected. That said I would probably use system states to reset everything, I presume it's more secure because even if the virtual machine is hacked, the vulnerability will stay, but any rogue software is wiped.

"...different Windows versions (care to see your code blow up on XP?), all of these make your code unportable. If you change every C:\Users\%USERNAME%\AppData\Local instance to %LOCALAPPDATA% then your code will be portable and my eyes will stop bleeding!"

No need to be hatin' on Peteris, especially since your %LOCALAPPDATA% suggestion doesn't work in XP by default. That variable was first introduced in Vista, and needs to be added manually in XP for your tip to work:

First, as one former poster commented, you should use %APPDATA% and %LOCALAPPDATA% for portability.

Second, you should not clear IE cache that way. It's not portable to multiple languages/windows versions either. The correct way of clearing IE (7+) cache is to execute the API call of "ClearMyTracksByProcess" from InetCpl.cpl, like this:

REM Clear IE cache - 1 and 8 are Temp Files and History. Use 255 for all if you want to clear everything.
RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 8
RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 1

This will also remove the necessity of your C program.

Third, in the event you're running these all on a machine not knowing what browsers are on it, you'll get a ton of feedback and errors to STDOUT in the command line. Try adding:
1> nul 2>&1
to the end of each line to redirect STDOUT and STDERR to nul so it makes the execution silent, or at least pipe it to a file.

Hi, I am new to batch files and all. I use google chrome. I am very interested in just clearing ONLY browsing history, cookies, cache. I still want to be able to have bookmarks and saved passwords. Can someone please tell me how? Thanks

So I'm looking to make a script to go through all users profiles on the local machine and clear out site specfic Cache NOT all just for a specific domain. having a hard time since you cant use the extended attributes on the Temporary Internet Files folder... any thoughts?

I disagree with some posters. For example when you work inside a company, running a non-managed executable is not an option. Also many users don't have admin access to their PC\laptop. So sometimes Windows scripts are the only way to go.
If you are worried about the location within the filesystem, you can add a section in the script to fetch the location, and populate it instead of hardcoding.

KeyName [\\Machine\]FullKey
Machine Name of remote machine - omitting defaults to the current machine
Only HKLM and HKU are available on remote machines
FullKey ROOTKEY\SubKey
ROOTKEY [ HKLM | HKCU | HKCR | HKU | HKCC ]
SubKey The full name of a registry key under the selected ROOTKEY
ValueName The value name, under the selected Key, to delete
When omitted, all subkeys and values under the Key are deleted
/ve delete the value of empty value name

<no>

/va delete all values under this key
/f Forces the deletion without propmt

Examples:

REG DELETE HKLM\Software\MyCo\MyApp\Timeout
Deletes the registry key Timeout and its all subkeys and values

Hello does anyone have a script to delete chrome and firefox cache, history, on MACHINE STARTUP?
We have hundreds of machines with hundreds of users and want to implement a script in group policy where it deletes it from every machine on startup..thanks

Thank you, dude.
I am using your code to clean all the crap that is getting dumped in my machine everyday. I am cleaning Firefox and Chrome. I really do not care about IE as I use it may be once in a year or something like that.

I scheduled it to a batch script that kills FF and Chrome before cleaning. I start everyday with fresh set of cookies. Thanks for the code.

A lot has changed since this was written. None of the .bat files work anymore. Cookies from sites are hidden inside particular files now and sometimes they are encrypted. So a "Find" search will not highlight them. You will not be able to find which files they are in. For Chrome just put a link in the Bookmarks Toolbar to "chrome://settings/cookies". Then remove the cookies directly.