Creating a cookie outside of a web-browser (E.g., With VBScript)
A very random request - and trust me, I wish I didn't have to do it either. Essentially, a customers users are using a website that plays up with some other technology we roll out. We've exhausted all other routes in getting things to work properly, so I'm now in workaround / bodge territory.
I've found an option on the website which does make things work. However, it's undesirable (And needless convoluted unfortunately) for us to direct the users to configure this themselves.
Therefore, what I'd like / need to do is to set a cookie on computer logon. All the cookie contains is "0:-" which just disables the feature we need to disable.
Again, I realise this is highly undesirable but assuming I can find a way out of this, then I'll be out of the woods. Ideally in VBScript, but really anything that is invisible to the users is good.
Just for context, this is a Server 2008 R2 domain with Vista and Windows 7 Clients running IE8 and IE9. That is the scope for work and all I need to get working!
I'm happy to hear alternative suggestions, but the end result is that we want to automatically disable this websites feature for our users.
Any help gratefully received.
Edit: I've tagged C# as I'm reasonabl开发者_C百科y familiar with that too (From a SysAdmin PoV)
Thanks,
Dan
Well, I think I may have cracked it in C#. Here are my code extracts:
[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()
{
IESetProtectedModeCookie("http://url.co.uk", "name", "data=blah; expires = Sat,01-Jan-2012 00:00:00 GMT; path=/", 0x10);
IESetProtectedModeCookie("http://url.co.uk", "name", "data=blah; expires = Sat,01-Jan-2012 00:00:00 GMT; path=/", 0);
return true;
}
It seems to have to set the cookie twice (With two different flags) in order to get consistent behaviour regardless of whether the website has been visited before or not.
Added the following lines to catch non-protected mode, too. This appears to cover all bases and works on IE9 and IE8:
[DllImport("wininet.dll", CharSet = CharSet.Auto, SetLastError = true)]
private static extern bool InternetSetCookie(string url, string name, string data);
InternetSetCookie("http://url.co.uk", "Name", "data=blah; expires = Sat,01-Jan-2012 00:00:00 GMT; path=/");
You cannnot disable the features if no cookie one found. So when a user opens the application and doesn't have a cookie yet you disable the functionality?
Maybe make a different logon url for those users that sends some control variable or accesses a different url as opposed to the normal users. You could direct them to this url by a link on their desktop for example?
[Update: Since my initial reply was completely rubbish...]
- Generally speaking, cookies are plain text.
- IE cookies are built like that [You probably want to read this, too - since you need FILETIME values to build your own cookie].
- Then, on Win7, you'll find cookies stored in
%userprofile%\AppData\Roaming\Microsoft\Windows\Cookies\Low
With these building blocks, you now should be able to build a solution that fits your needs.
[And another update: You should take also take a look at the interaction of IE's index.dat - a cookie (file) registry - and the cookie itself. Maybe you need to a) register your cookie in index.dat manually, or - if this doesn't work - b) delete index.dat after you created the cookie file (IE will rebuild it then when the browser starts the next time).]
精彩评论