求教如何判断网络是否通!~急!~
要求用VB.net判断,我的网络是否通,如果发现不通了1分钟后重启计算机!~请问那位好心人写一下代码,小弟在些谢过了!~~ --------------------编程问答-------------------- 没有人回答我吗,晕死 --------------------编程问答--------------------
[DllImport("Wininet.dll")]--------------------编程问答-------------------- Private Declare Function InternetGetConnectedStateEx Lib "wininet.dll" Alias "InternetGetConnectedStateExA" _
private static extern bool InternetGetConnectedState(out int lpdwFlags, int dwReserved);
(ByRef lpdwFlags As Long, _
ByVal lpszConnectionName As String, _
ByVal dwNameLen As Long, _
ByVal dwReserved As Long _
) As Long
Public Enum NetConnTypeConstants
INTERNET_CONNECTION_MODEM = &H1&
INTERNET_CONNECTION_LAN = &H2&
INTERNET_CONNECTION_PROXY = &H4&
INTERNET_RAS_INSTALLED = &H10&
INTERNET_CONNECTION_OFFLINE = &H20&
INTERNET_CONNECTION_CONFIGURED = &H40&
End Enum --------------------编程问答-------------------- 简单的
bool System.Windows.Forms.SystemInformation.Network --------------------编程问答-------------------- 顶,UP最精解! --------------------编程问答--------------------
--------------------编程问答-------------------- 也可以使用Ping的办法。。。
Namespace My
Class MyApplication
Private Sub MyApplication_Startup(ByVal sender As Object, ByVal e As Microsoft.VisualBasic.ApplicationServices.StartupEventArgs) Handles Me.Startup
Call SetConnectionStatus(My.Computer.Network.IsAvailable)
End Sub
Private Sub MyApplication_NetworkAvailabilityChanged(ByVal sender As Object, ByVal e As Microsoft.VisualBasic.Devices.NetworkAvailableEventArgs) Handles Me.NetworkAvailabilityChanged
Call SetConnectionStatus(My.Computer.Network.IsAvailable)
End Sub
Private Sub SetConnectionStatus(ByVal Connected As Boolean)
With My.Forms.Form2.ConnectedStatusLabel
If Connected Then
.Image = My.Resources.connected.ToBitmap
.Text = My.Resources.ConnectedText
Else
.Image = My.Resources.disconnected.ToBitmap
.Text = My.Resources.DisconnectedText
End If
End With
End Sub
End Class
End Namespace
If My.Computer.Network.Ping("198.01.01.01") Then
MsgBox("Server pinged successfully.")
Else
MsgBox("Ping request timed out.")
End If
││博客空间:http://blog.csdn.net/lovingkiss
││资源下载:http://download.csdn.net/user/lovingkiss
││Email:loving-kiss@163.com
││联系方式:Q66840199 项目、聊天、咨询、探讨、统统收费,呵呵......
╚---------------------------------------------------------------------------------------------------------ō*︻$▅▆▇◤
补充:.NET技术 , VB.NET