Create a Cookie (Outside of a website)

From: Monsoir (PILOTDAN)24 Sep 2011 10:56
To: Rich 5 of 6

Haha, fair point. I don't believe there's anything build into Group Policy (Or even Group Policy Preferences) to do this, but obviously that's how the answer will be deployed.

 

I'll try and give more details without giving away specific info as it's niche and I don't want to be Googled.

 

Basically, the customers users are using www.sitea.com but it doesn't seem to play nicely with some of the other technology we use. We've exhausted all other technical avenues and while we've found a few workarounds the only way to make it perform properly is by disabling "Feature A" on the website.

 

This has no effect for the user (They wouldn't even notice), but it's very convoluted and they would need to do it on a regular basis as the cookie doesn't last long. Additionally, their network is set up in such a way that cookies aren't persistent.

 

We have absolutely no influence over www.sitea.com and they would just laugh me off the phone. (They're huge, and they will not care!)

From: Monsoir (PILOTDAN)24 Sep 2011 15:31
To: ALL6 of 6
Think I've found a way:

code:
    [DllImport("ieframe.dll", CharSet = CharSet.Auto, SetLastError = true)]
    private static extern bool IESetProtectedModeCookie(string url, string name, string data, int flags);
 
    public static bool SetWinINETCookieString()
    {
      return IESetProtectedModeCookie("http://url.co.uk", "name", "data=blah; expires = Sat,01-Jan-2012 00:00:00 GMT; path=/", 0x10);
 
    }


Slim pickings on Google to say the least, that shit has taken me 2 hours!

I'm not even convinced it's correct, AND it returns false but it seems to work here on IE9. Just need to test it on IE8.

The final product which creates cookies in both protected and unprotected mode, regardless of whether the user has visited the site before or not. Tested on IE8 and IE9:

code:
    class Program
 
    {
        [DllImport("ieframe.dll", CharSet = CharSet.Auto, SetLastError = true)]
        private static extern bool IESetProtectedModeCookie(string url, string name, string data, int flags);
 
        [DllImport("wininet.dll", CharSet = CharSet.Auto, SetLastError = true)]
        private static extern bool InternetSetCookie(string url, string name, string data);
 
 
        static void Main(string[] args)
        {
 
        IESetProtectedModeCookie("http://url.co.uk", "Name", "data; expires = Sat,01-Jan-2012 00:00:00 GMT; path=/", 0);
        IESetProtectedModeCookie("http://url.co.uk", "Name", "data; expires = Sat,01-Jan-2012 00:00:00 GMT; path=/", 0x10);
        InternetSetCookie("http://url.co.uk", "Name", "data; expires = Sat,01-Jan-2012 00:00:00 GMT; path=/");
 
        }
    }


Just need to make the date dynamic.
EDITED: 24 Sep 2011 17:20 by PILOTDAN