zoukankan      html  css  js  c++  java
  • wininet.dll 使用锦集

    //判断计算机是否能够连接到Internet的API 
    //wininet.dll是Windows应用程序网络相关模块。该文件隶属于%WINDOWSSYSTEM32目录下动态库连接文件。该文件不可缺失,属于关键链接库。当文件丢失或者损坏时,届时将无法完成Explorer进程(即桌面以及基于该进程的IE浏览器等,可使用不基于IE浏览器进行访问网络)
    
    [DllImport("wininet.dll")] 
    public extern static bool InternetGetConnectedState( outint Description, int ReservedValue ) ;
    
    //创建一个调用API函数(封装为C#方式).
    ///<summary>
    /// 查看网络是否连接到公网
    ///</summary>
    ///<returns>返回Ture:可以连接到Internet,False则连接不上</returns>
    public static bool IsConnectedToInternet( )
    {
          int Desc ;
          return InternetGetConnectedState(out Desc, 0);
    }
    

    第二种设置永久cookie 

    using System;   
      
    using System.Text;   
      
    using System.Runtime.InteropServices;   
      
    namespace ConsoleApplication1   
      
    {   
      
        class Program   
      
        {   
      
            /// <summary>   
      
            /// 设置cookie   
      
            /// </summary>   
      
            [DllImport("wininet.dll", CharSet = CharSet.Auto, SetLastError = true)]   
      
            public static extern bool InternetSetCookie(string lpszUrlName, string lbszCookieName, string lpszCookieData);   
      
            /// <summary>   
      
            /// 获取cookie   
      
            /// </summary>   
      
            [DllImport("wininet.dll", CharSet = CharSet.Auto, SetLastError = true)]   
      
            public static extern bool InternetGetCookie(   
      
              string url, string name, StringBuilder data, ref int dataSize);   
      
            static void Main(string[] args)   
      
            {   
      
                //获取旧的   
      
                StringBuilder cookie = new StringBuilder(new String(' ',2048));   
      
                int datasize = cookie.Length;   
      
                bool b= InternetGetCookie("http://community.csdn.net", null, cookie, ref datasize);   
      
                //删除旧的   
      
                foreach (string fileName in System.IO.Directory.GetFiles(System.Environment.GetFolderPath(Environment.SpecialFolder.Cookies)))   
      
                {   
      
                    if (fileName.ToLower().IndexOf("csdn") > 0)   
      
                    {   
      
                        System.IO.File.Delete("csdn");   
      
                    }   
      
                }   
      
                //生成新的   
      
                foreach (string c in cookie.ToString().Split(';'))   
      
                {   
      
                    string[] item = c.Split('=');   
      
                    string name = item[0];   
      
                    string value = item[1] + ";expires=Sun,22-Feb-2099 00:00:00 GMT";   
      
                    InternetSetCookie("http://community.csdn.net",name,value);   
      
                    InternetSetCookie("http://forum.csdn.net", name, value);   
      
                    InternetSetCookie("http://webim.csdn.net", name, value);   
      
                }   
      
            }   
      
        }   
      
    }
    

     若要免登录可以调用 免登录

         Process.Start("iexplore.exe", LinkAddress.CookiesFind); 

      

  • 相关阅读:
    区块链基础语言(十二)——Go语言跳转语句
    区块链基础语言(十一)——Go语言循环语句
    区块链基础语言(十)——Go语言选择语句
    区块链基础语言(九)——Go语言运算符
    区块链技术语言(八)——Go语言常量
    区块链基础语言(七)——Go语言变量
    区块链基础语言(六)——Go语言数据类型
    区块链基础语言(五)——Go语言结构
    区块链基础语言(四)——Go语言工程管理
    人生苦短,我用 Python
  • 原文地址:https://www.cnblogs.com/sharpmap/p/6571714.html
Copyright © 2011-2022 走看看