IESetProtectedModeCookie function
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(
_In_ LPCWSTR lpszURL,
_In_ LPCWSTR lpszCookieName,
_In_ LPWSTR pszCookieData,
_In_ 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 sets cookie data:
INTERNET_COOKIE_THIRD_PARTY (0x10)
Indicates that the cookie being set is a third-party cookie.
INTERNET_FLAG_RESTRICTED_ZONE (0x00020000)
Indicates that the cookie being set is associated with an untrusted site.
Return value
If this function succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code.
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.
Examples
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"https://contoso.com", L"CookieName", szCookieVal, NULL);
if (hr != S_OK)
{
hr = HRESULT_FROM_WIN32(GetLastError());
}
}
}
}
return hr;
Requirements
Minimum supported client |
Windows XP with SP2 |
Minimum supported server |
Windows Server 2003 |
Product |
Internet Explorer 8 |
Header |
Iepmapi.h |
Library |
Iepmapi.lib |
DLL |
Ieframe.dll |
See also
Reference
Conceptual
Protected Mode Broker Functions
Other Resources
Understanding and Working in Protected Mode Internet Explorer