heymega
heymega

Reputation: 9391

Run IE11 in Hidden Mode

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?

Upvotes: 0

Views: 501

Answers (1)

Lucas Damiani
Lucas Damiani

Reputation: 77

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"));

Upvotes: 1

Related Questions