【问题标题】:Run IE11 in Hidden Mode在隐藏模式下运行 IE11
【发布时间】:2015-01-20 01:45:32
【问题描述】:

我需要在隐藏模式下运行 IE11(不显示浏览器),这样我就可以设置一个 cookie。这是我之前在 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
            });

如果我在带有 IE11 的机器上使用它,它会显示浏览器。有没有办法可以做到这一点?

【问题讨论】:

标签: c# internet-explorer internet-explorer-11


【解决方案1】:

您建议您使用不同的方式设置 cookie:

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

您可以在下面找到使用它的示例:

bool b = InternetSetCookie("http://localhost/", "keyname", "value; Expires = + DateTime.Now.AddDays(10).ToString("R"));

【讨论】:

  • 这很有趣 - 有没有办法让它在 Chrome 和 Firefox 上工作,或者这是否明确适用于 IE?
  • 不幸的是,它是针对 IE 的 :(
  • 我已经创建了一个 POC 并按预期在 IE 中工作。即使它不支持其他浏览器,它仍然非常有用,我可能会走这条路。谢谢
猜你喜欢
  • 1970-01-01
  • 2015-03-29
  • 2010-11-02
  • 1970-01-01
  • 1970-01-01
  • 2020-05-30
  • 2016-05-16
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多