Create a Cookie (Outside of a website)

From: Dan (HERMAND)23 Sep 2011 14:58
To: ALL1 of 6

Hi All,

 

Odd request, I know - but I need to manually build a cookie using a script or some-such. It's a long story, and I won't bore you with the details, but we need to do this and the cookie is completely generic.

 

It's just a simple "Feature On" / "Feature Off" preference that we need to mandate.

 

Ideally I'd like to do it with a login script and VBS, but I'm open to any ideas before this issue gives me a heart attack :(

 

Does anyone have any ideas?

 

Thanks!

 

Dan

From: Peter (BOUGHTONP)23 Sep 2011 22:00
To: Dan (HERMAND) 2 of 6
You can't have a generic cookie - it needs to be linked to a particular domain/ip (even if that's localhost or a network IP).

Also, they're browser-specific, so you need to say if you're using IE only or any other browsers that might be involved.

(No idea if it's actually possible to manually create a cookie, but it certainly requires both those bits of info if it is going to be done - if you need a solution that doesn't involve either/both of those bits, it's not a cookie.)
From: Rich23 Sep 2011 23:06
To: Dan (HERMAND) 3 of 6
This sounds like the sort of thing that Group Policy was designed for.

quote:
I won't bore you with the details


Which is all well and good but not good for getting an answer with any value. :)
From: Dan (HERMAND)24 Sep 2011 10:50
To: Peter (BOUGHTONP) 4 of 6
Sorry Peter - bit of a rush post yesterday.

quote:
You can't have a generic cookie - it needs to be linked to a particular domain/ip (even if that's localhost or a network IP).


When I say generic, I meant that the data inside isn't encoded or user specific or anything. It's literally Feature=0.

quote:
Also, they're browser-specific, so you need to say if you're using IE only or any other browsers that might be involved.


Sorry, yes - we're using IE8 and IE9 on Win 7 and Vista (Well, Server 2008 Terminal Services)
From: Dan (HERMAND)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: Dan (HERMAND)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 HERMAND