locked
InternetGetCookie and InternetSetCookie issues

    Question

  • We have an  exe which runs in  SYSTEM account.In SYSTEM account  InternetGetCookie/InternetSetCookie seems to work only within that instance.When the instance exits then in new instance InternetCookie is not able to retrieve the older name value pairs using InternetGetCookie.Also InternetSetCookie always returns 2 though it seems to do the work.Using process monitor I could see file system activity in C:\windows\system32\config\systemprofile\Roaming\microsoft\windows\Cookies folder but in no case could actually see the files using explorer or command line.Even launching command line in SYSTEM account does'nt help.

    These issues only happen in develoiper preview but windows 7 and vista does'nt have these issues.Also in developer preview the issue is only when running in SYSTEM account.In Protected admin mode and full admin mode no issues in developer preview.

    • Moved by Keith-Microsoft Support Wednesday, October 05, 2011 2:38 PM (From:Windows Developer Preview: General OS questions )
    Wednesday, October 05, 2011 5:53 AM

Answers

  • Hi AM,

    There are know issues with using WinInet in that context and so you should not count on WinInet API calls working for your scenario.  You could manage your cookies yourself in code (simply look for and add your cookie headers) or move to the managed world and use System.Net (which has a cookie container).

    -Jeff


    Jeff Sanders (MSFT)
    Tuesday, November 08, 2011 1:41 PM
    Moderator

All replies

  • Hello,

    so I can easily repro:

     bool success;
     success = InternetSetCookie(L"http://somesite2.com", L"cookie2", L"SomeData2 = Test; expires = Sat,01-Jan-2012 00:00:00 GMT");

     cout << success << endl;
     cout << GetLastError() << endl;

     DWORD dwLen;
     
     if (InternetGetCookie(L"http://somesite2.com", L"cookie2", NULL, &dwLen))
     {
      CString s;
      LPTSTR pstrTarget = s.GetBuffer(dwLen);
      success = InternetGetCookie(L"http://somesite2.com", L"cookie2", pstrTarget, &dwLen);
      wcout << pstrTarget << endl;
      s.ReleaseBuffer(dwLen);

     }
     cout << GetLastError() << endl;

     then if I comment out the SetCookie above and run it again then I get the false return and the getlasterror return of 2 (ERROR_FILE_NOT_FOUND).  This only reproduces under the system account.

    we can look for a workaround before beta if needed.

    could you submit the bug via the connect site

    Thank you for posting your feedback, we want to make sure we get the right info including your log files.  Can you also submit feedback using the Windows Feedback Tool from the Connect Site associated with your Windows Developer Preview program? If you’re an MSDN subscriber, the information on how to join the Connect program is included on the download page where you installed Windows Developer Preview.  There’s a link to the Connect site and an invitation code that you can click on to join using a Windows Live ID account. If you’re not an MSDN subscriber follow this limited use link to join the Connect program and then follow the steps here

    thanks! mike

    • Marked as answer by Chris Sells Monday, October 10, 2011 2:47 PM
    • Unmarked as answer by AMSingh Friday, October 21, 2011 4:11 PM
    Thursday, October 06, 2011 9:44 PM
    Moderator
  • thanks a lot.I have submitted the bug.

    I don't need any time frame but only question is will this bug be fixed or in other words is the bug acceptable and will be fixed.

    Let me know if possible about  workaround except not using SYSTEM account.


    Windows developer
    Friday, October 07, 2011 2:18 PM
  • I have submitted the bug on connect site.

    But no reply/feedback till now.

    As per reply the bug is reproduceable.

    Is this bug or a feature on windows 8.

    Will it be fixed.

    Is there any workaround.


    Windows developer
    Friday, October 21, 2011 4:13 PM
  • Hello AM,

    Please be aware that WinInet is not supported in a service on in the context of the System Account.  This is not a new restriction.  I have a blog that speaks a little about problems related to the registry and it may offer some relief for your problem, but the real solution is to move to a supported scenario such as WinHttp.

    http://blogs.msdn.com/b/jpsanders/archive/2009/07/09/wininet-used-in-thread-impersonation.aspx

    -Jeff

     


    Jeff Sanders (MSFT)
    Wednesday, October 26, 2011 4:01 PM
    Moderator
  • We are using WinHttp for server communication and are using WinInet InternetSetCookie/InternetGetCookie for cookie persistence.

    Persistent Cookies are not supported in WinHttp.

    Also from test application I can see  InternetSetCookie/InternetGetCookie can be used standalone without any other calls to WinInet API's.

    I mean if I just make a sample application which just set/get Cookies then that application does'nt work properly in SYSTEM account.

    1) Cookies does'nt persist.

    2) InternetSetCookie always returns 2 as error code.

    Will this mean that persistent cookie will not at all be supported for SYSTEM account in Windows 8.


    Windows developer
    Friday, November 04, 2011 6:44 AM
  • Hi AM,

    There are know issues with using WinInet in that context and so you should not count on WinInet API calls working for your scenario.  You could manage your cookies yourself in code (simply look for and add your cookie headers) or move to the managed world and use System.Net (which has a cookie container).

    -Jeff


    Jeff Sanders (MSFT)
    Tuesday, November 08, 2011 1:41 PM
    Moderator