• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C#获取ADSL所有宽带连接名称

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

1.通过注册表获取,缺点,兼容性差

1 //RegistryKey userKey = Registry.CurrentUser;
2 //RegistryKey key = userKey.OpenSubKey(@"RemoteAccess\Profile");
3 //string[] keysList = key.GetSubKeyNames();//获取当前创建的adsl宽带列表


2.通过api获取,兼容性比上面好

#region 获取adsl所有宽带连接名称

[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
public struct RasEntryName      //define the struct to receive the entry name
{
    public int dwSize;
    [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256 + 1)]
    public string szEntryName;
    #if WINVER5
     public int dwFlags;
     [MarshalAs(UnmanagedType.ByValTStr,SizeConst=260+1)]
     public string szPhonebookPath;
    #endif
}

[DllImport("rasapi32.dll", CharSet = CharSet.Auto)]

public extern static uint RasEnumEntries(
    string reserved,              // reserved, must be NULL
    string lpszPhonebook,         // pointer to full path and file name of phone-book file
    [In, Out]RasEntryName[] lprasentryname, // buffer to receive phone-book entries
    ref int lpcb,                  // size in bytes of buffer
    out int lpcEntries             // number of entries written to buffer
);

public static List<string> GetAllAdslName()
{
    List<string> list = new List<string>();
    int lpNames = 1;
    int entryNameSize = 0;
    int lpSize = 0;
    RasEntryName[] names = null;
    entryNameSize = Marshal.SizeOf(typeof(RasEntryName));
    lpSize = lpNames * entryNameSize;
    names = new RasEntryName[lpNames];
    names[0].dwSize = entryNameSize;
    uint retval = RasEnumEntries(null, null, names, ref lpSize, out lpNames);

    //if we have more than one connection, we need to do it again
    if (lpNames > 1)
    {
        names = new RasEntryName[lpNames];
        for (int i = 0; i < names.Length; i++)
        {
            names[i].dwSize = entryNameSize;
        }
        retval = RasEnumEntries(null, null, names, ref lpSize, out lpNames);
    }

    if (lpNames > 0)
    {
        for (int i = 0; i < names.Length; i++)
        {
            list.Add(names[i].szEntryName);
        }
    }
    return list;
}

#endregion

鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
[转]c#(winform)中ComboBoxListBox添加项完全解决发布时间:2022-07-13
下一篇:
c#Oracle远程连接方式plsql连接oracle11g64位发布时间:2022-07-13
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap