none
ieGetProtectedModeCookie fails on 64bit Windows 7 with 64bit Outlook RRS feed

  • Question

  • I have an Outlook addin that can be configured from a website via cookies. The addin reads the cookies to set parameters sent in cookies by the website. Reading cookies on W7 x64 with OL 2010 x64 fails, OL 2003 and OL2007 work. Do I need to change something to make this work in x64 environment?

    Here is a log of results on an x32 system and x64 system and code snippets (note: the cookie request is made twice, first time returns the size).

    Windows Vista x32 with OL 2007
    1/28/2012 9:25:25 PM IsPrtctd = True
    1/28/2012 9:25:25 PM Try IEGetProtectedModeCookie 1
    1/28/2012 9:25:25 PM IEGetProtectedModeCookie 1, lReturn = -2147024774
    1/28/2012 9:25:25 PM Try IEGetProtectedModeCookie 2, CkSz = 888
    1/28/2012 9:25:25 PM IEGetProtectedModeCookie 2, lReturn = 0
    1/28/2012 9:25:25 PM g_Cookies = ki_u=21288725-09ca-09b2-aaba-b88cef9c05d3; ki_t=1321585559158%3B1327803673712%3B1327803673712%3B5%3B11; webusertracking=5001569; mypwn_login_firstname=John; __utma=255648521.1797070755.1310304532.1327638859.1327803673.7; __utmz=255648521.1310304532.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); _vis_opt_s=5%7C; _vis_opt_exp_12_split=2; _vis_opt_exp_12_combi=2; _vis_opt_exp_14_split=4; _vis_opt_exp_14_combi=4; _vis_opt_exp_14_goal_208=1;

    Windows 7 x64 with OL 2010 x64
    1/28/2012 9:45:04 PM IsPrtctd = True
    1/28/2012 9:45:04 PM Try IEGetProtectedModeCookie 1
    1/28/2012 9:45:04 PM IEGetProtectedModeCookie 1, lReturn = -2147221164
    1/28/2012 9:45:04 PM Try IEGetProtectedModeCookie 2, CkSz = 1
    1/28/2012 9:45:04 PM IEGetProtectedModeCookie 2, lReturn = -2147221164
    1/28/2012 9:45:04 PM g_Cookies =

     

     

    CODE
        <DllImport("ieframe.dll", EntryPoint:="IEGetProtectedModeCookie")> _
        Public Function IEGetProtectedModeCookie( _
            <[In](), MarshalAs(UnmanagedType.LPWStr)> ByVal lpszURL As String, _
            <[In](), MarshalAs(UnmanagedType.LPWStr)> ByVal lpszCookieName As String, _
            <MarshalAs(UnmanagedType.LPWStr)> ByVal pszCookieData As StringBuilder, _
            ByRef pcchCookieData As UInteger, _
            ByVal dwFlags As UInteger) As Integer
        End Function

     

        Private Sub GetCookies(ByVal CkURL As String)
            'If the URL is in protected mode and we are in Vista+ then get low integrity cookie
            If IsPrtctd(CkURL) And g_OSVrsn >= 6 Then
                My.Computer.FileSystem.WriteAllText("C:\Temp\Test.txt", ControlChars.NewLine & Now.ToString & " IsPrtctd = True", True)
                g_Cookies = GtPrtctdMdCk(CkURL)
            Else
                My.Computer.FileSystem.WriteAllText("C:\Temp\Test.txt", ControlChars.NewLine & Now.ToString & " IsPrtctd = False", True)
                g_Cookies = GtCk(CkURL)
            End If

            My.Computer.FileSystem.WriteAllText("C:\Temp\Test.txt", ControlChars.NewLine & Now.ToString & " g_Cookies = " & g_Cookies, True)

        End Sub

     

        Public Function GtPrtctdMdCk(ByVal strCkURL As String) As String
            Dim strBuffer As New StringBuilder(2)
            Dim CkSz As UInteger = 1
            Dim lReturn As Integer = 0
            Dim Cookies As String = ""

            Try
                My.Computer.FileSystem.WriteAllText("C:\Temp\Test.txt", ControlChars.NewLine & Now.ToString _
                                                    & " Try IEGetProtectedModeCookie 1", True)

                lReturn = IEGetProtectedModeCookie( _
                                            strCkURL, _
                                            vbNullString, _
                                            strBuffer, _
                                            CkSz, _
                                            0)
                My.Computer.FileSystem.WriteAllText("C:\Temp\Test.txt", ControlChars.NewLine & Now.ToString _
                                                    & " IEGetProtectedModeCookie 1, lReturn = " & lReturn, True)
                If lReturn <> 0 Then
                    'use the new cookie size
                    strBuffer = strBuffer.Append(Space(CInt(CkSz) + 1))

                    My.Computer.FileSystem.WriteAllText("C:\Temp\Test.txt", ControlChars.NewLine & Now.ToString _
                                                        & " Try IEGetProtectedModeCookie 2, CkSz = " & CkSz, True)

                    lReturn = IEGetProtectedModeCookie( _
                                                strCkURL, _
                                                vbNullString, _
                                                strBuffer, _
                                                CkSz, _
                                                0)
                    My.Computer.FileSystem.WriteAllText("C:\Temp\Test.txt", ControlChars.NewLine & Now.ToString _
                                                        & " IEGetProtectedModeCookie 2, lReturn = " & lReturn, True)
                End If
                If lReturn = 0 Then
                    'remove the null on the end
                    Cookies = Left$(strBuffer.ToString, strBuffer.Capacity - 1) & ";"
                End If

            Catch ex As Exception
                My.Computer.FileSystem.WriteAllText("C:\Temp\Test.txt", ControlChars.NewLine & Now.ToString _
                                                    & " Exception: " & ex.ToString, True)
            End Try

            GtPrtctdMdCk = Cookies


        End Function


    John C Svercek
    • Moved by Carey FrischMVP Sunday, January 29, 2012 9:42 PM Moved to more appropriate forum category (From:Windows 7 Miscellaneous)
    • Moved by Max Meng Monday, January 30, 2012 9:02 AM Moving to a more appropriate forum (From:Outlook IT Pro Discussions)
    Sunday, January 29, 2012 4:45 AM

Answers

  • Working with Microsoft Support we have determined that this is actually a known issue with 64 bit machines, Windows 7 and maybe Vista (Vista has not been confirmed). Microsoft has no plans to fix the issue at this time. The workaround is to start a low integrity process to get the information and pass the information back to the medium integrity app.

    Seems like Microsoft could make this information more available, even the support person spent a week on this before he discovered it was a known issue.


    John C Svercek

    • Marked as answer by JCSvercek Wednesday, February 15, 2012 3:02 AM
    Wednesday, February 15, 2012 3:02 AM

All replies

  • Hi John

    hope you get answer faster in appropriate MSDN forum

    http://social.msdn.microsoft.com/Forums/en-US/categories

    Regards

    Milos

     


    Sunday, January 29, 2012 5:45 PM
  • Probably data structure alignment is wrong in your declaration of external function on 64 bit system.
    Monday, January 30, 2012 12:16 PM
  • Thanks DamianD for the suggestion. I tried changing the last two parameters to UInt64 with the same result. I also came across another thread where the problem was resolved by adding CharSet:=CharSet.Unicode to the definition. Still got the same results.

    Any other suggestions?

    John

     


    John C Svercek
    Tuesday, January 31, 2012 4:47 AM
  • i managed to get it working on 64 bit win 7 with following declaration:

     

    [DllImport("ieframe.dll", CharSet = CharSet.Unicode)]
    public static extern int IEGetProtectedModeCookie( string lpszURL, string lpszCookieName, StringBuilder pszCookieData,
               ref int pcchCookieData, uint dwFlags);
    

    However, please remember that you must check if your url is from Protected Mode, but i guess you already know that.

    Tuesday, January 31, 2012 10:47 AM
  • DamianD, since I am using VB.Net I translated the declaration to this

        <DllImport("ieframe.dll", CharSet:=CharSet.Unicode)> _
        Function IEGetProtectedModeCookie(ByVal lpszURL As String, _
            ByVal lpszCookieName As String, _
            ByVal pszCookieData As StringBuilder, _
            ByRef pcchCookieData As Integer, _
            ByVal dwFlags As UInteger) As Integer
        End Function

    with the same results.

    Are you using a 64 bit machine for dev? I am developing on a 32bit and compiling to 64bit. That's not supposed to be an issue, and the IEisProtectedModeURL function works but I cannot think of anything else. Any other suggestions?


    John C Svercek
    Wednesday, February 1, 2012 2:39 AM
  • yes, i;m using full 64 bit env (win + office). However i compile add-in to anycpu, no idea if this could interfere, but i do not think so. Tell me, is url you are checking for from internal network? Please try to use this function with something from internet, like http://www.google.com (remember to visit this page in browser before running this code).

    Wednesday, February 1, 2012 9:13 AM
  • I double checked the IEIsProtectedModeURL function and it works fine (not protected (UAC off) returns 1/protected returns 0). I tested 32 bit high and low cookies and that works. I tested high and low cookies in 64 bit. The only failing mode is 64 bit high. This was with the URL I have always used.

    I then tried using google and it fails with the same error code.

    I also tried building with Any CPU but that did not even load.

    I'm at a loss as to what to try next other then to build a 64bit dev machine. Any other suggestions?

     


    John C Svercek
    Thursday, February 2, 2012 2:20 AM
  • Why building managed .net add-in as anycpu makes it not load at all? i suspect that compiling bitness might be the issue after all.
    Thursday, February 2, 2012 11:37 AM
  • It turns out the issue is with Win 7 not 32/64. The cookies are not readable on a 32bit Win 7 installation either. My dev machine is Vista 32. That just seems really strange, I am going try a different Win7 32 bit machine. Maybe its just the test machine. Then again it is failing on my Win7 64bit, things that make you go Hmmmmmmm. Anyway I ramble as I just found this out and I need to digest it a bit.
    John C Svercek
    Thursday, February 2, 2012 4:09 PM
  • Working with Microsoft Support we have determined that this is actually a known issue with 64 bit machines, Windows 7 and maybe Vista (Vista has not been confirmed). Microsoft has no plans to fix the issue at this time. The workaround is to start a low integrity process to get the information and pass the information back to the medium integrity app.

    Seems like Microsoft could make this information more available, even the support person spent a week on this before he discovered it was a known issue.


    John C Svercek

    • Marked as answer by JCSvercek Wednesday, February 15, 2012 3:02 AM
    Wednesday, February 15, 2012 3:02 AM