Calls the standard InternetSetCookieEx from a higher-integrity user context. Creates a cookie with a specified name that is associated with a specified URL.
Syntax
HRESULT IESetProtectedModeCookie( LPCWSTR lpszURL, LPCWSTR lpszCookieName, LPWSTR pszCookieData, DWORD dwFlags );
Parameters
lpszURL [in] A pointer to a null-terminated string that contains the URL for which the cookie should be set. lpszCookieName [in] A pointer to a null-terminated string that contains the name to associate with this cookie. If this pointer is NULL, then no name is associated with the cookie.pszCookieData [in] A pointer to a null-terminated string that contains the data to be associated with the new cookie.dwFlags [in] Flags that control how the function retrieves cookie data:INTERNET_COOKIE_EVALUATE_P3PIf this flag is set and the dwReserved parameter is not NULL, then the dwReserved parameter is cast to an LPCTSTR that points to a Platform for Privacy Protection (P3P) header for the cookie in question.INTERNET_COOKIE_THIRD_PARTYIndicates that the cookie being set is a third-party cookie.INTERNET_FLAG_RESTRICTED_ZONEIndicates that the cookie being set is associated with an untrusted site.
INTERNET_COOKIE_EVALUATE_P3P
INTERNET_COOKIE_THIRD_PARTY
INTERNET_FLAG_RESTRICTED_ZONE
Return Value
Returns S_OK if successful, or an error value otherwise.
Remarks
To create a persistent cookie, add an expires name/value pair to the cookie data. The format of the value must be DAY, DD-MMM-YYYY HH:MM:SS GMT. DAY is a three-letter abbreviation for the day of the week, DD is the day of the month, MMM is a three-letter abbreviation for the month, YYYY is the year, and HH:MM:SS is the time of day in 24-hour format.
expires
DAY, DD-MMM-YYYY HH:MM:SS GMT
DAY
DD
MMM
YYYY
HH:MM:SS
Example
The following example shows how to use the IESetProtectedModeCookie method to create a persistent cookie in the protected mode cookie store. HRESULT hr = E_FAIL; TCHAR szTime[100]; TCHAR szCookieVal[MAX_PATH]; COleDateTime oDate; SYSTEMTIME systime; SecureZeroMemory(szCookieVal, sizeof(TCHAR) * MAX_PATH); oDate = COleDateTime::GetCurrentTime(); //set expiry to a day. oDate+= COleDateTimeSpan(1, 0, 0, 0); if (oDate.GetAsSystemTime(systime)) { if (InternetTimeFromSystemTime(&systime, INTERNET_RFC1123_FORMAT, szTime, MAX_PATH)) { if (SUCCEEDED(StringCchPrintf(szCookieVal, MAX_PATH,L"%s;expires=%s", L"CookieValue",szTime))) { hr = IESetProtectedModeCookie(L"http://contoso.com", L"CookieName", szCookieVal, NULL); if (hr != S_OK) { hr = HRESULT_FROM_WIN32(GetLastError()); } } } } return hr;
The following example shows how to use the IESetProtectedModeCookie method to create a persistent cookie in the protected mode cookie store.
HRESULT hr = E_FAIL; TCHAR szTime[100]; TCHAR szCookieVal[MAX_PATH]; COleDateTime oDate; SYSTEMTIME systime; SecureZeroMemory(szCookieVal, sizeof(TCHAR) * MAX_PATH); oDate = COleDateTime::GetCurrentTime(); //set expiry to a day. oDate+= COleDateTimeSpan(1, 0, 0, 0); if (oDate.GetAsSystemTime(systime)) { if (InternetTimeFromSystemTime(&systime, INTERNET_RFC1123_FORMAT, szTime, MAX_PATH)) { if (SUCCEEDED(StringCchPrintf(szCookieVal, MAX_PATH,L"%s;expires=%s", L"CookieValue",szTime))) { hr = IESetProtectedModeCookie(L"http://contoso.com", L"CookieName", szCookieVal, NULL); if (hr != S_OK) { hr = HRESULT_FROM_WIN32(GetLastError()); } } } } return hr;
Function Information
Stock Implementationieframe.dllCustom ImplementationNoHeaderiepmapi.hImport libraryiepmapi.libMinimum availabilityInternet Explorer 8Minimum operating systems Windows XP SP2
See Also
Protected Mode Broker Functions, IEGetProtectedModeCookie, InternetSetCookieEx, Understanding and Working in Protected Mode Internet Explorer