【问题标题】:How to clear IE WebBrowser Control cookies如何清除 IE WebBrowser Control cookie
【发布时间】:2020-11-20 00:57:59
【问题描述】:

我已经尝试过 INTERNET_OPTION_END_BROWSER_SESSION ,但是这不会删除 cookie 我发现的唯一方法是使用 RunDll32.exe InetCpl 删除 IE 浏览器 cookie 本身。 cpl,ClearMyTracksByProcess 2. 这工作得很好但是这会打开 IE 清除历史对话框 有没有其他方法可以删除清除 WebBrowser Control cookie

【问题讨论】:

  • @Jimi 感谢您的回复,我出于其他原因需要持久性 cookie,并且只想在某些操作时清除 cookie
  • @Deepak-MSFT 你对此有什么想法吗?
  • this thread,有一个选项256 表示Do not Show GUI when running the cache clear。您可以尝试将这些值组合在一起,看看它是否可以隐藏对话框窗口。根据答案,通过将值相加,我们可以获得聚合功能。所以你可以试试RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 258
  • @YuZhou 我试过了,还是IE清除cookies对话框

标签: c++ windows winforms internet-explorer webbrowser-control


【解决方案1】:

不要进入这么复杂的东西。只需下载 ccleaner 或打开它(如果您已经拥有),然后转到自定义清理 -> 应用程序并勾选标题 Internet Explorer ->“Cookie 和其他站点数据”下的复选框

如果要删除或禁用 IE,请转到设置-> 或控制面板(如果您没有 Windows 10 操作系统),然后转到程序和功能 -> 卸载程序 -> 启用某些 Windows 功能 -> 取消勾选复选框“ Internet Explorer 9 或 11(无论您拥有哪个版本)” 希望你喜欢这个答案并为你工作

【讨论】:

  • 我必须从我的应用程序中清除 IE cookie,而不是从第三方应用程序中清除。抱歉,这不是我想要的
  • 好的,然后参考这个网站 - support.microsoft.com/en-in/help/17442/…
  • 我正在寻找通过命令行清除cookies
【解决方案2】:

可以参考这个链接静默清除IE cookie https://www.codeproject.com/Articles/15319/A-Cleanup-API-for-Windows

__declspec( dllexport ) BOOL Delete_IECookies(BOOL bDeleteCookies, 
                                                       BOOL bDeleteCookiesIndex)
{
    TCHAR szUserProfile[200]; 
    TCHAR szFilePath[200];
    HANDLE hCacheEnumHandle  = NULL;
    LPINTERNET_CACHE_ENTRY_INFO lpCacheEntry = NULL;
    DWORD  dwSize = 4096; // initial buffer size

    // Delete index.dat if requested. Be sure that index.dat is not locked.
    if(bDeleteCookiesIndex)
    {
        // Retrieve from environment user profile path.
        ExpandEnvironmentStrings("%userprofile%", szUserProfile, 
                                                         sizeof(szUserProfile)); 
        wsprintf(szFilePath, "%s%s", szUserProfile, "\\Cookies\\index.dat");

        DeleteFile(szFilePath);

        if(!bDeleteCookies) return TRUE;
    }
    
    // Enable initial buffer size for cache entry structure.
    lpCacheEntry = (LPINTERNET_CACHE_ENTRY_INFO) new char[dwSize];
    lpCacheEntry->dwStructSize = dwSize;
    
    // URL search pattern (1st parameter) options are:  "cookie:", "visited:", 
    // or NULL ("*.*").
    hCacheEnumHandle = FindFirstUrlCacheEntry(_T("cookie:") /* in */, 
                                 lpCacheEntry /* out */, &dwSize /* in, out */);
    
    // First, obtain handle to internet cache with FindFirstUrlCacheEntry
    // for late use with FindNextUrlCacheEntry.
    
    if(hCacheEnumHandle != NULL) 
    {
         DeleteUrlCacheEntry(lpCacheEntry->lpszSourceUrlName);
    }
    else
    {
        switch(GetLastError())
        {
            case ERROR_INSUFFICIENT_BUFFER:
                lpCacheEntry = (LPINTERNET_CACHE_ENTRY_INFO) new char[dwSize];
                lpCacheEntry->dwStructSize = dwSize;

                // Repeat first step search with adjusted buffer, exit if not
                // found again (in practice one buffer's size adustment is  
                // always OK).
                hCacheEnumHandle = FindFirstUrlCacheEntry(NULL, lpCacheEntry, 
                                                                       &dwSize);
                if(hCacheEnumHandle != NULL) 
                {
                    DeleteUrlCacheEntry(lpCacheEntry->lpszSourceUrlName);
                    break;        
                }
                else
                {
                    // FindFirstUrlCacheEntry fails again, return.
                    return FALSE; 
                }
            default:
                FindCloseUrlCache(hCacheEnumHandle);
                return FALSE;
        }
    }
    
    // Next, use hCacheEnumHandle obtained from the previous step to delete 
    // subsequent items of cache.

    do 
    {
         // Notice that return values of FindNextUrlCacheEntry (BOOL) and 
         // FindFirstUrlCacheEntry (HANDLE) are different.

         if(FindNextUrlCacheEntry(hCacheEnumHandle, lpCacheEntry, &dwSize))
         {
            DeleteUrlCacheEntry(lpCacheEntry->lpszSourceUrlName);
         }
         else
         {
             switch(GetLastError())
             {
                 case ERROR_INSUFFICIENT_BUFFER:
                    lpCacheEntry = (LPINTERNET_CACHE_ENTRY_INFO) 
                                                               new char[dwSize];
                    lpCacheEntry->dwStructSize = dwSize;

                    // Repeat next step search with adjusted buffer, exit if 
                    // error comes up again ((in practice one buffer's size 
                    // adustment is always OK).

                    if(FindNextUrlCacheEntry(hCacheEnumHandle, lpCacheEntry, 
                                                                       &dwSize)) 
                    {
                        DeleteUrlCacheEntry(lpCacheEntry->lpszSourceUrlName);
                        break;          
                    }
                    else
                    {
                        // FindFirstUrlCacheEntry fails again, return.
                        FindCloseUrlCache(hCacheEnumHandle);
                        return FALSE; 
                    }
                    break;
                 case ERROR_NO_MORE_ITEMS:
                     FindCloseUrlCache(hCacheEnumHandle);
                     return TRUE; 
                 default:
                     FindCloseUrlCache(hCacheEnumHandle);
                     return FALSE;
             }
         } 
    } while (TRUE);

    return FALSE; // never here
}

【讨论】:

    猜你喜欢
    • 2011-01-03
    • 2017-08-31
    • 2010-12-13
    • 2013-11-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多