internal static void ShellExecuteDefaultBrowser(Uri uri) { UnsafeNativeMethods.ShellExecuteInfo sei = new UnsafeNativeMethods.ShellExecuteInfo(); sei.cbSize = Marshal.SizeOf(sei); sei.fMask = UnsafeNativeMethods.ShellExecuteFlags.SEE_MASK_FLAG_DDEWAIT; /* * There is a bug on Windows Vista (with IE 7): ShellExecute via SEE_MASK_CLASSNAME fails for an * http[s]:// URL. It works fine for file://. The cause appears to be that the DDE command template * defined in HKCR\IE.AssocFile.HTM\shell\opennew\ddeexec is used: [file://%1",-1,,,,,]. On XP, the * the key used is (supposedly) HKCR\htmlfile\shell\opennew\ddeexec, and its value is ["%1",,-1,0,,,,]. * The workaround here is to add the SEE_MASK_CLASSNAME flag only for non-HTTP URLs. For HTTP, * "plain" ShellExecute just works, incl. with Firefox/Netscape as the default browser. */ if (uri.Scheme != Uri.UriSchemeHttp && uri.Scheme != Uri.UriSchemeHttps) { sei.fMask |= UnsafeNativeMethods.ShellExecuteFlags.SEE_MASK_CLASSNAME; sei.lpClass = ".htm"; // The default browser is looked up by this. } sei.lpFile = uri.ToString(); // It's safe to use Uri.ToString since there's an inheritance demand on it that prevents spoofing by subclasses. if (!UnsafeNativeMethods.ShellExecuteEx(sei)) { throw new InvalidOperationException(SR.Get(SRID.FailToLaunchDefaultBrowser), new System.ComponentModel.Win32Exception(/*uses the last Win32 error*/)); } }
internal static void ShellExecuteDefaultBrowser(Uri uri) { UnsafeNativeMethods.ShellExecuteInfo sei = new UnsafeNativeMethods.ShellExecuteInfo(); sei.cbSize = Marshal.SizeOf(sei); sei.fMask = UnsafeNativeMethods.ShellExecuteFlags.SEE_MASK_FLAG_DDEWAIT; /* * There is a * * * * * */ if (uri.Scheme != Uri.UriSchemeHttp && uri.Scheme != Uri.UriSchemeHttps) { sei.fMask |= UnsafeNativeMethods.ShellExecuteFlags.SEE_MASK_CLASSNAME; sei.lpClass = ".htm"; // The default browser is looked up by this. } sei.lpFile = uri.ToString(); // It's safe to use Uri.ToString since there's an inheritance demand on it that prevents spoofing by subclasses. if (!UnsafeNativeMethods.ShellExecuteEx(sei)) { throw new InvalidOperationException(SR.Get(SRID.FailToLaunchDefaultBrowser), new System.ComponentModel.Win32Exception(/*uses the last Win32 error*/)); } }
internal static void ShellExecuteDefaultBrowser(Uri uri) { UnsafeNativeMethods.ShellExecuteInfo shellExecuteInfo = new UnsafeNativeMethods.ShellExecuteInfo(); shellExecuteInfo.cbSize = Marshal.SizeOf(shellExecuteInfo); shellExecuteInfo.fMask = UnsafeNativeMethods.ShellExecuteFlags.SEE_MASK_FLAG_DDEWAIT; if (uri.Scheme != Uri.UriSchemeHttp && uri.Scheme != Uri.UriSchemeHttps) { shellExecuteInfo.fMask |= UnsafeNativeMethods.ShellExecuteFlags.SEE_MASK_CLASSNAME; shellExecuteInfo.lpClass = ".htm"; } shellExecuteInfo.lpFile = uri.ToString(); if (!UnsafeNativeMethods.ShellExecuteEx(shellExecuteInfo)) { throw new InvalidOperationException(SR.Get("FailToLaunchDefaultBrowser"), new Win32Exception()); } }