首先,建立一个Windows窗体专案,在窗体上增加两个按钮,启用网络按钮和暂停网络按钮,并且如下操作: 项目-->添加引用-->com-->Microsoft Shell Controls And Automation。
完整代码:
Imports Shell32
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim flag As Boolean = My.Computer.Network.IsAvailable
Me.Text = flag
End Sub
''' <summary>
''' 设置网络断开和连接
''' </summary>
''' <param name="StrNetWorkConnection"></param>
''' <param name="StrVerb"></param>
''' <returns></returns>
''' <remarks></remarks>
Private Function SetNetworkAdapter(ByVal StrNetWorkConnection As String, ByVal StrVerb As String) As Boolean
Dim Shell As Shell32.Shell = New Shell32.Shell()
首先,建立一个Windows窗体专案,在窗体上增加两个按钮,启用网络按钮和暂停网络按钮,并且如下操作: 项目-->添加引用-->com-->Microsoft Shell Controls And Automation。完整代码:Imports Shell32Public Class Form1Private Sub Form1_Load(ByVal sender As System.Ob
szEntryName(256) As Byte
szDeviceType(16) As Byte
szDeviceName(129) As Byte 'extra byte added for alignment in VB5
End Type
Private Type RASCONNSTATUS 'version 4.0
dwSize As Long
rasState As RASCONNSTATE
dwError As Long
szDeviceType(16) As Byte
szDeviceName(130) As Byte 'two extra bytes added for alignment in VB5
End Type
'Enumerates intermediate states to a connection.
Private Const RASCS_PAUSED As Long = &H1000
Private Const RASCS_DONE As Long = &H2000
Public Enum RASCONNSTATE
Dim netinterfaces() As NetworkInterface
netinterfaces = NetworkInterface.GetAllNetworkInterfaces
通过NetworkInterface.GetAllNetworkInterfaces的方法返回所有的
网络
接口,然后使用for each循环获得各个
网络
接口的信息。