【发布时间】:2014-10-22 12:37:32
【问题描述】:
我正在使用以下代码在 Windows 8.1 的系统默认浏览器中成功打开请求的 URL:
public static void OpenUrlInDefaultBrowser(string url)
{
var httpKey = Registry.ClassesRoot.OpenSubKey(@"http\shell\open\command");
if (httpKey == null || httpKey.GetValue(string.Empty) == null)
return;
var cmd = httpKey.GetValue(string.Empty) as string;
if (cmd != null)
{
try
{
if (cmd.Length > 0)
{
string[] splitStr;
string fileName;
string args;
if (cmd.Substring(0, 1) == "\"")
{
splitStr = cmd.Split(new[] { "\" " }, StringSplitOptions.None);
fileName = splitStr[0] + "\"";
args = cmd.Substring(splitStr[0].Length + 2);
}
else
{
splitStr = cmd.Split(new[] { " " }, StringSplitOptions.None);
fileName = splitStr[0];
args = cmd.Substring(splitStr[0].Length + 1);
}
System.Diagnostics.Process.Start(fileName, args.Replace("%1", url));
}
}
catch (Exception)
{
// handle exception
}
}
httpKey.Close();
}
但是,在我的 Windows Server 2008 R2 VM 上,同样的代码会打开 Internet Explorer(该机器上的默认浏览器),但只会加载 URL res://iesetup.dll/SoftAdmin.htm。 IE 设置为关闭增强安全模式。 Chrome 在这台机器上可以正常工作。
仅调用Process.Start(url) 也无法打开请求的 URL。
当我从“运行...”菜单执行以下操作时,它按预期工作:"C:\Program Files\Internet Explorer\iexplore.exe" http://example.com。 PowerShell 中的 start-process http://example.com 也是如此。
【问题讨论】:
-
您可以在管理员模式下运行您的应用程序吗?可能与权限有关
-
好主意,但我以管理员身份运行。
-
通过更改一些注册表来禁用 IE 安全模式警告,social.technet.microsoft.com/Forums/windowsserver/en-US/…
-
@Ryios 这些建议的注册表更改无效。
-
您是否阅读过他谈到将其更改为 64 位和 32 位版本的帖子?进行更改后您是否注销并重新登录?
标签: c# internet-explorer windows-server-2008 process.start