zoukankan      html  css  js  c++  java
  • WebBrowser 登录windows集成验证的网站

    引用地址 http://www.cnblogs.com/gsyifan/archive/2010/08/27/1810022.html

      1 public partial class Form1 : Form,IOleClientSite,IServiceProvider,IAuthenticate
      2     {
      3         public Form1()
      4         {
      5             InitializeComponent();
      6         }
      7 
      8        
      9         private void Form1_Load(object sender, EventArgs e)
     10         {
     11                 wb.Dock = DockStyle.Fill;//WebBrowser wb = new WebBrowser();
     12                 string oURL = "about:blank";
     13                 wb.Navigate(oURL);//多做这一步不知道是干嘛的,求高手解答
     14 
     15 
     16                 object obj2 = wb.ActiveXInstance;
     17                 IOleObject oc = obj2 as IOleObject;
     18                 oc.SetClientSite(this as IOleClientSite);
     19                 oURL = "要登录的目标地址";
     20                 wb.Navigate(oURL);
     21 
     22         }
     23 
     24         #region windows集成登录
     25         public static Guid IID_IAuthenticate = new Guid("79eac9d0-baf9-11ce-8c82-00aa004ba90b");
     26         public const int INET_E_DEFAULT_ACTION = unchecked((int)0x800C0011);
     27         public const int S_OK = unchecked((int)0x00000000);
     28         #region IOleClientSite Members
     29 
     30         public void SaveObject()
     31         {
     32             // TODO: Add Form1.SaveObject implementation
     33         }
     34 
     35         public void GetMoniker(uint dwAssign, uint dwWhichMoniker, object
     36         ppmk)
     37         {
     38             // TODO: Add Form1.GetMoniker implementation
     39         }
     40 
     41         public void GetContainer(object ppContainer)
     42         {
     43             ppContainer = this;
     44         }
     45 
     46         public void ShowObject()
     47         {
     48             // TODO: Add Form1.ShowObject implementation
     49         }
     50 
     51         public void OnShowWindow(bool fShow)
     52         {
     53             // TODO: Add Form1.OnShowWindow implementation
     54         }
     55 
     56         public void RequestNewObjectLayout()
     57         {
     58             // TODO: Add Form1.RequestNewObjectLayout implementation
     59         }
     60 
     61         #endregion
     62 
     63         #region IServiceProvider Members
     64 
     65         public int QueryService(ref Guid guidService, ref Guid riid, out IntPtr ppvObject)
     66         {
     67             int nRet = guidService.CompareTo(IID_IAuthenticate); // Zero returned if the compared objects are equal
     68             if (nRet == 0)
     69             {
     70                 nRet = riid.CompareTo(IID_IAuthenticate); // Zero returned if the compared objects are equal
     71                 if (nRet == 0)
     72                 {
     73                     ppvObject = Marshal.GetComInterfaceForObject(this,
     74                     typeof(IAuthenticate));
     75                     return S_OK;
     76                 }
     77             }
     78             ppvObject = new IntPtr();
     79             return INET_E_DEFAULT_ACTION;
     80         }
     81 
     82         #endregion
     83 
     84         #region IAuthenticate Members
     85 
     86         public int Authenticate(ref IntPtr phwnd, ref IntPtr pszUsername, ref IntPtr pszPassword)
     87         {
     88             
     89             IntPtr sUser = Marshal.StringToCoTaskMemAuto("viewlog_wxsy");
     90             IntPtr sPassword = Marshal.StringToCoTaskMemAuto("34wuiHM9RECSXmeUyk");
     91 
     92             pszUsername = sUser;
     93             pszPassword = sPassword;
     94             return S_OK;
     95         }
     96 
     97         #endregion
     98 
     99        
    100         #endregion
    101 }
    102 
    103 #region COM Interfaces
    104 
    105     [ComImport,
    106     Guid("00000112-0000-0000-C000-000000000046"),
    107     InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
    108     public interface IOleObject
    109     {
    110         void SetClientSite(IOleClientSite pClientSite);
    111         void GetClientSite(IOleClientSite ppClientSite);
    112         void SetHostNames(object szContainerApp, object szContainerObj);
    113         void Close(uint dwSaveOption);
    114         void SetMoniker(uint dwWhichMoniker, object pmk);
    115         void GetMoniker(uint dwAssign, uint dwWhichMoniker, object ppmk);
    116         void InitFromData(IDataObject pDataObject, bool
    117         fCreation, uint dwReserved);
    118         void GetClipboardData(uint dwReserved, IDataObject ppDataObject);
    119         void DoVerb(uint iVerb, uint lpmsg, object pActiveSite,
    120         uint lindex, uint hwndParent, uint lprcPosRect);
    121         void EnumVerbs(object ppEnumOleVerb);
    122         void Update();
    123         void IsUpToDate();
    124         void GetUserClassID(uint pClsid);
    125         void GetUserType(uint dwFormOfType, uint pszUserType);
    126         void SetExtent(uint dwDrawAspect, uint psizel);
    127         void GetExtent(uint dwDrawAspect, uint psizel);
    128         void Advise(object pAdvSink, uint pdwConnection);
    129         void Unadvise(uint dwConnection);
    130         void EnumAdvise(object ppenumAdvise);
    131         void GetMiscStatus(uint dwAspect, uint pdwStatus);
    132         void SetColorScheme(object pLogpal);
    133     }
    134 
    135     [ComImport,
    136     Guid("00000118-0000-0000-C000-000000000046"),
    137     InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
    138     public interface IOleClientSite
    139     {
    140         void SaveObject();
    141         void GetMoniker(uint dwAssign, uint dwWhichMoniker, object ppmk);
    142         void GetContainer(object ppContainer);
    143         void ShowObject();
    144         void OnShowWindow(bool fShow);
    145         void RequestNewObjectLayout();
    146     }
    147 
    148     [ComImport,
    149     GuidAttribute("6d5140c1-7436-11ce-8034-00aa006009fa"),
    150     InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIUnknown),
    151     ComVisible(false)]
    152     public interface IServiceProvider
    153     {
    154         [return: MarshalAs(UnmanagedType.I4)]
    155         [PreserveSig]
    156         int QueryService(ref Guid guidService, ref Guid riid, out IntPtr
    157         ppvObject);
    158     }
    159 
    160     [ComImport, GuidAttribute("79EAC9D0-BAF9-11CE-8C82-00AA004BA90B"),
    161     InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIUnknown),
    162     ComVisible(false)]
    163     public interface IAuthenticate
    164     {
    165         [return: MarshalAs(UnmanagedType.I4)]
    166         [PreserveSig]
    167         int Authenticate(ref IntPtr phwnd,
    168         ref IntPtr pszUsername,
    169         ref IntPtr pszPassword
    170         );
    171     }
    172 
    173     #endregion
  • 相关阅读:
    错误设置子网掩码的结果
    子网掩码
    网络笔记
    网络笔记
    命名空间
    命名空间
    多重继承和虚继承
    多重继承和虚继承
    windows抓包程序
    windows抓包程序
  • 原文地址:https://www.cnblogs.com/contraII/p/2772756.html
Copyright © 2011-2022 走看看