Click to Rate and Give Feedback
MSDN
MSDN Library
Web Development
Protected Mode
Reference
Functions
 IESetProtectedModeCookie Function
IESetProtectedModeCookie Function
New for Windows Internet Explorer 8

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_P3P
If 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_PARTY
Indicates that the cookie being set is a third-party cookie.
INTERNET_FLAG_RESTRICTED_ZONE
Indicates that the cookie being set is associated with an untrusted site.

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.

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;    

Function Information

Stock Implementationieframe.dll
Custom ImplementationNo
Headeriepmapi.h
Import libraryiepmapi.lib
Minimum availabilityInternet Explorer 8
Minimum operating systems Windows XP SP2

See Also

Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Integrity Level Limitation      EricLaw [MSFT]   |   Edit   |   Show History
This API can only be called from a Low or Medium integrity process, not a High integrity process. When called from a High integrity process, the API returns ERROR_INVALID_ACCESS.
Tags What's this?: Add a tag
Flag as ContentBug
Processing
© 2010 Microsoft Corporation. All rights reserved. Terms of Use | Trademarks | Privacy Statement
Page view tracker