| 网站首页 | VB.Net实例分析 | .Net技术文摘 | 下载中心 | VB.Net书籍笔记 | .Net源码 | VBS脚本与组件调用 | Windows2008技术文摘 | 给我们留言 | 
最新公告:

  没有公告

您现在的位置: 乐博网 >> VB.Net应用技巧 >> 技术文摘正文
最新推荐 更多内容
[组图]禁用启用本地连接的几种方法(乐博网原创)
禁用启用本地连接的几种方法(乐博网原创)
作者:Rock    来源:乐博网原创     更新时间:2011-4-2

 用.net禁用启用本地连接的四种方法,殊途同归,来自乐博网   推荐第三种,需要交流就来乐博网的.net超级qq群40797788 

方法一:

源代码如下

需要引用shell32.dll   在system32目录下

VB2005源代码如下:

Public Class Form1

    Private Shared ReadOnly Property ControlPanelFolder()

        Get
            Dim shell As New Shell32.Shell()
            Return shell.NameSpace(3)
        End Get

    End Property

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Try

            Dim retVal As Shell32.Folder = Nothing
            For Each lob_k As Shell32.FolderItem In ControlPanelFolder.Items
                If lob_k.Name = "网络连接" Then
                    retVal = lob_k.GetFolder()
                    MessageBox.Show("乐博网lob.cn")
                    Exit For
                End If
            Next
            Dim lob_y As Shell32.FolderItem = Nothing
            For Each folderItem As Shell32.FolderItem In retVal.Items
                MessageBox.Show(folderItem.Name)
                If InStr(folderItem.Name.ToLower(), "本地连接".ToLower()) Then
                    lob_y = folderItem
                    Exit For
                End If
            Next
            For Each lob_u As Shell32.FolderItemVerb In lob_y.Verbs
                If lob_u.Name = "禁用(&B)" Then
                    lob_u.DoIt()
                    MessageBox.Show("乐博网提示:禁用")
                Else
                    MessageBox.Show("乐博网提示:启用")
                    lob_u.DoIt()
                End If
                Exit For
            Next
        Catch
        End Try

    End Sub

End Class

方法二:   乐博网推荐

效果图:

 

需要引用 System.Management

操作方法:在菜单中选择 “项目”---“添加引用”-- System.Management  

 

VB2005源代码如下:

Dim MyobjectQuery As New System.Management.ObjectQuery("select * from Win32_NetworkAdapter")

Dim MySearcher As New System.Management.ManagementObjectSearcher(MyobjectQuery)

For Each Mgmt As System.Management.ManagementObject In MySearcher.Get()

CheckedListBox1.Items.Add(Mgmt("Caption").ToString)

MessageBox.Show(Mgmt("Caption").ToString & " : 乐博网Device - " & Mgmt("DeviceID").ToString)

If Mgmt("DeviceID").ToString = "8" Then

Mgmt.InvokeMethod("Enable", Nothing)

End If

Next

 

[1] [2] 下一页

  • 上一篇:

  • 下一篇: 没有了
  • 【字体: 】【打印此文】【关闭窗口
      相关文章:(只显示最新16条)
    VB.Net禁止和启用本地网络连接的方法(2011-04-01完善)

    | 设为首页 | 加入收藏 | 联系站长 | | 友情链接 | 版权申明 |
    乐博网欢迎各种媒体转载我们的原创作品[转载请注明出处];我们鼓励更多VB.Net开发者一起加入研究与探讨;如发现文章访问错误、内容错误或版权疑问、内容有违相关法律(如涉及政治、色情、反动或散布虚假有害信息)等情况,请及时向我们举报,我们将及时纠正!
    联系邮箱:Shiny#vip.qq.com (#替换为@) QQ交流群: 40797788 [闽ICP备05014267号]