| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1388 人关注过本帖
标题:请教高手用VB.NET启用和禁用网卡的程序!
只看楼主 加入收藏
binghe6610
Rank: 2
等 级:论坛游民
帖 子:273
专家分:61
注 册:2009-2-23
结帖率:86.67%
收藏
已结贴  问题点数:20 回复次数:2 
请教高手用VB.NET启用和禁用网卡的程序!
可以获取到网卡,不知道怎样启用和禁用
 Dim searcher As New ManagementObjectSearcher("SELECT * FROM Win32_NetworkAdapterConfiguration")

        Dim share As ManagementObject

        ()

        For Each share In searcher.Get()

            If Not (share.Item("IPAddress") Is Nothing) Then

             Me.ListBox1.Items.Add(share("Description").ToString.Trim)
            End If

        Next share
搜索更多相关主题的帖子: 网卡 NET 
2010-10-26 17:30
不说也罢
Rank: 13Rank: 13Rank: 13Rank: 13
等 级:贵宾
威 望:39
帖 子:1481
专家分:4989
注 册:2007-10-7
收藏
得分:20 
下面是一个例子,楼主拿去参考一下
以下是FORM1的全部代码,运行此示例,需要你在项目中引用COM——Ms Shell32(在system32文件夹下的shell32.dll)
程序代码:
Imports System.Runtime.InteropServices.GCHandle
Imports System.Runtime.InteropServices.GCHandleType

Public Class Form1
    Private Const NetConnect As Integer = &H31
    Private Function ExcNetLinkMenu(ByVal AdapterName As String, ByVal MenuName As String) As Boolean
        On Error Resume Next
        Dim Shell32 As Object
        Dim lNameLenPtr As Integer
        Dim lNameLen As Integer
        Dim Handle As System.Runtime.InteropServices.GCHandle
        Dim GCHandle As System.Runtime.InteropServices.GCHandleType
        Handle = System.Runtime.InteropServices.GCHandle.Alloc("NetConnection", Pinned)
        lNameLenPtr = Handle.AddrOfPinnedObject.ToInt32

        Dim mShell As Shell32.Shell = New Shell32.Shell
        Dim NetConnection As Shell32.Folder
        Dim FolderItem As Shell32.FolderItem
        Dim NetConnectionItem As New Shell32.ShellFolderItem
        Dim verb As Shell32.FolderItemVerb
        NetConnection = mShell.NameSpace(49)
        If lNameLenPtr = 0 Then
            ExcNetLinkMenu = False
            GoTo exitfunction
        End If
        Dim flag As Boolean
        flag = False
        For Each FolderItem In NetConnection.Items
            If FolderItem.Name = AdapterName Then
                NetConnectionItem = FolderItem
                flag = True
                Exit For
            End If
        Next FolderItem
        If flag = False Then
            ExcNetLinkMenu = False
            GoTo exitfunction
        End If
        For Each verb In NetConnectionItem.Verbs
            If verb.Name = MenuName Then
                flag = True
                verb.DoIt()
                ExcNetLinkMenu = True
                GoTo exitfunction
            End If
        Next verb
        If flag = False Then
            ExcNetLinkMenu = False
            GoTo exitfunction
        End If
exitfunction:
        mShell = Nothing
        NetConnection = Nothing
        FolderItem = Nothing
        NetConnectionItem = Nothing
        verb = Nothing
    End Function

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        '把 本地连接换成你要控制的本地连接的名字
        Dim blnRelust As Boolean
        blnRelust = ExcNetLinkMenu("本地连接", "停用(&B)")
        If blnRelust Then
            Console.Write("停用成功")
        Else
            blnRelust = ExcNetLinkMenu("本地连接", "禁用(&B)")
        End If
        If blnRelust Then
            Console.Write("停用成功")
        Else
            Console.Write("停用失败")
        End If
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Dim blnRelust As Boolean
        blnRelust = ExcNetLinkMenu("本地连接", "启用(&A)")
        If blnRelust Then
            Console.Write("启用成功")
        Else
            Console.Write("启用失败")
        End If
    End Sub
End Class

===================================================
讨厌C#的行尾的小尾巴;和一对大括号{ }
===================================================
2010-10-28 12:32
binghe6610
Rank: 2
等 级:论坛游民
帖 子:273
专家分:61
注 册:2009-2-23
收藏
得分:0 
谢谢你的代码,有时间测试一下
2010-10-30 11:28
快速回复:请教高手用VB.NET启用和禁用网卡的程序!
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.018584 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved