0

I have a requirement to run IE11 in hidden mode (Without showing the browser) so I can descretely set a cookie. This is the code I previously used which worked in IE9

            cmd = (String)Registry.GetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\Classes\IE.AssocFile.HTM\shell\opennew\command", "", null);
            url = "http://www.stackoverflow.com";

            Process process = Process.Start(new ProcessStartInfo()
            {
                FileName = cmd,
                Arguments = url,
                WindowStyle = ProcessWindowStyle.Hidden
            });

If I use this on a machine with IE11 it shows the browser. Is there a way that I can do this?

heymega
  • 9,215
  • 8
  • 42
  • 61

1 Answers1

1

You suggest you a different way to set a cookie:

[DllImport("wininet.dll", CharSet=CharSet.Auto, SetLastError=true)]
static extern bool InternetSetCookie(string lpszUrl, string lpszCookieName, string lpszCookieData);

You can find below an example to use it:

bool b = InternetSetCookie("http://localhost/", "keyname", "value; Expires = + DateTime.Now.AddDays(10).ToString("R"));
  • This is very interesting - Is there anyway to make this work with Chrome and Firefox or is this explicitly for IE? – heymega Jan 20 '15 at 09:49
  • 1
    Unfortunately it is specific for IE :( – Lucas Damiani Jan 20 '15 at 11:34
  • I've created a POC and its working in IE as expected. Even though it doesn't support other browsers, It's still extremely useful & I will probably go down this route. Thank you – heymega Jan 20 '15 at 12:31