ProtectedModeHelper
사용법 : int i = ProtectedModeHelper.LaunchInternetExplorer(url);
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
namespace IEProtectedModeTest
{
// Engineered from iepmapi.h in the Windows SDK
[StructLayout(LayoutKind.Sequential)]
internal struct IELAUNCHURLINFO
{
public int cbSize;
public int dwCreationFlags;
}
// PInvoke.net
// http://www.pinvoke.net/default.aspx/Structures/PROCESS_INFORMATION.html
[StructLayout(LayoutKind.Sequential)]
internal struct PROCESS_INFORMATION
{
public IntPtr hProcess;
public IntPtr hThread;
public int dwProcessId;
public int dwThreadId;
}
/// <summary>
/// Native methods class.
/// </summary>
internal static class SafeNativeMethods
{
/// <summary>
/// The Internet Explorer UI library.
/// </summary>
private const string InternetExplorerUILibrary = "ieframe.dll";
/// <summary>
/// Launch a URL with Internet Explorer. Works with IE's protected
/// mode.
/// </summary>
/// <param name="url">The URI to navigate to.</param>
/// <param name="pProcInfo">Process information struct by reference
/// that will contain the opened process ID.</param>
/// <param name="lpInfo">The launch information struct.</param>
/// <returns>Returns a value indicating whether the native call was
/// successful.</returns>
[DllImport(InternetExplorerUILibrary)]
internal static extern bool IELaunchURL(
[MarshalAs(UnmanagedType.LPWStr)] string url,
ref PROCESS_INFORMATION pProcInfo,
ref IELAUNCHURLINFO lpInfo);
}
/// <summary>
/// Launch a protected mode IE and provide the process ID.
/// </summary>
public static class ProtectedModeHelper
{
/// <summary>
/// Launch Internet Explorer and return the PID. Requires Vista; an
/// Exception will be thrown on platforms prior to it.
/// </summary>
/// <param name="url">The url to navigate to. Providing null will
/// navigate the browser to the user's homepage.</param>
/// <returns>Returns the IE process ID if successful, or 0.</returns>
public static int LaunchInternetExplorer(string url)
{
if (Environment.OSVersion.Version.Major >= 6)
{
PROCESS_INFORMATION pi = new PROCESS_INFORMATION();
IELAUNCHURLINFO li = new IELAUNCHURLINFO();
li.cbSize = Marshal.SizeOf(typeof(IELAUNCHURLINFO));
return SafeNativeMethods.IELaunchURL(url, ref pi, ref li) ? pi.dwProcessId : 0;
}
else
{
throw new NotSupportedException("Protected Mode requires Windows Vista or later.");
}
}
/// <summary>
/// Launch Internet Explorer and returns the PID.
/// </summary>
/// <returns>Returns the IE process ID if successful, or 0.</returns>
public static int LaunchInternetExplorer()
{
return LaunchInternetExplorer(null);
}
}
}
IE10 랜더링 문제 해결 방안 (0) | 2013.05.28 |
---|---|
IE 신뢰사이트 (0) | 2012.03.30 |
IE Protected Mode 해제 (0) | 2012.03.30 |
IE 보호 모드에서 비보호 모드 프로세스 실행 (0) | 2012.03.30 |
IE Protected Mode API (0) | 2012.03.30 |