Programmatically clear cache in Internet Explorer 8 on Windows 7

I am writing a script to test Internet performance. It basically opens IE, browses a website (e.g. yahoo.com), exits IE, clears the cache and repeats

The problem I encountered is that the IE cache is not completely flushed. I know this because we looked at some packages and found a lot of HTTP requests for web page objects that returned 304, which means the cache was not cleared.

I tried two options, manually clearing the temp folder and using the command

RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 255 

but not one of them clears the cache completely. Is there a better way to do this?

+4
source share
1 answer

Internet Explorer . , cookie , .

, , :

@echo off

set DataDir=C:\Users\%USERNAME%\AppData\Local\Microsoft\Intern~1

del /q /s /f "%DataDir%"
rd /s /q "%DataDir%"

set History=C:\Users\%USERNAME%\AppData\Local\Microsoft\Windows\History

del /q /s /f "%History%"
rd /s /q "%History%"

set IETemp=C:\Users\%USERNAME%\AppData\Local\Microsoft\Windows\Tempor~1

del /q /s /f "%IETemp%"
rd /s /q "%IETemp%"

set Cookies=C:\Users\%USERNAME%\AppData\Roaming\Microsoft\Windows\Cookies

del /q /s /f "%Cookies%"
rd /s /q "%Cookies%"

, , :

C:\bin\regdelete.exe HKEY_CURRENT_USER "Software\Microsoft\Internet Explorer\TypedURLs"

, regdelete.exe. win32, ++, IE, .

regdelete.c:

#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <vector>
#include <string>
// compile as: mingw32-g++ regdelete.c -o regdelete.exe -mwindows

#define eq(s1,s2) (strcmp((s1),(s2))==0)

int WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR cmdLine, int nCmdShow) 
{ 
    if (!cmdLine || !strlen(cmdLine)) {
        printf("Usage: regdel.exe <HKEY> <path to regkey> - be careful not to delete whole registry\n");
        return 1;
    }

    int argc;
    LPWSTR *argv = CommandLineToArgvW(GetCommandLineW(), &argc);

    if (argc < 3) {
        printf("Usage: regdel.exe <HKEY> <path to regkey> - be careful not to delete whole registry\n");
        return 1;
    }

    char **argv8 = (char **)malloc(sizeof(char *) * argc);
    for (int i = 0; i<argc; i++) {
        int len = wcslen(argv[i]);
        argv8[i] = (char *)malloc(sizeof(char)*(len+1));
        wcstombs(argv8[i], argv[i], len+1);
    }

    HKEY hkey;
    if (eq(argv8[1], "HKEY_CLASSES_ROOT")) {
        hkey == HKEY_CLASSES_ROOT;
    }
    else if (eq(argv8[1], "HKEY_CURRENT_CONFIG")) {
        hkey = HKEY_CURRENT_CONFIG;
    }
    else if (eq(argv8[1], "HKEY_CURRENT_USER")) {
        hkey = HKEY_CURRENT_USER;
    }
    else if (eq(argv8[1], "HKEY_LOCAL_MACHINE")) {
        hkey = HKEY_LOCAL_MACHINE;
    }
    else if (eq(argv8[1], "HKEY_USERS")) {
        hkey = HKEY_USERS;
    }
    else {
        printf("Unknown hkey\n");
        return 1;
    }

    HKEY key;
    int status = RegOpenKeyEx(hkey, argv8[2], 0, KEY_ALL_ACCESS, &key);
    if (status != ERROR_SUCCESS) {
        printf("failed opening %s\n", argv8[2]);
        return 1;
    }

std::vector<std::string> vals;

for (unsigned int i = 0; ; i++) {
    DWORD size = 1024;
    char val[size+1];
    DWORD type;
    status = RegEnumValue(key, i, val, &size, NULL, &type, NULL, NULL);
    if (status == ERROR_NO_MORE_ITEMS) break;
    if (status == ERROR_SUCCESS) {
        vals.push_back(std::string(val));
        continue;
    }
    printf("failed enumerating %s\n", argv8[2]);
    return 1;
}

typedef std::vector<std::string>::iterator vsi;
for (vsi i = vals.begin(); i != vals.end(); i++) {
    status = RegDeleteValue(key, i->c_str());
    if (status != ERROR_SUCCESS) {
        printf("failed deleting %s\n", i->c_str());
        return 1;
    }
}

return 0;
}

, regdelete.exe .

+1

All Articles