vb 检测网络是否断开
有一个Command1控件,Click后检测一次网络是否断开断开则msgbox"网络已断开。"没断开则msgbox"网络没有断开,自动断开!"然后自动断开网络。请大家给出...
有一个Command1控件,Click后检测一次网络是否断开
断开则msgbox "网络已断开。"
没断开则msgbox "网络没有断开,自动断开!"
然后自动断开网络。
请大家给出代码谢谢 展开
断开则msgbox "网络已断开。"
没断开则msgbox "网络没有断开,自动断开!"
然后自动断开网络。
请大家给出代码谢谢 展开
2个回答
展开全部
Private Sub Command1_Click()
Dim OpenFile, i
CreateObject("wscript.shell").run "cmd /c ping www.baidu.com>nul 2>nul&&echo yes>""tmp""||echo no>""tmp""", 0, 1
Open App.Path & "\tmp" For Input As #1
Do Until EOF(1)
Line Input #1, i
DoEvents
OpenFile = OpenFile & i & NL
Loop
If Right(OpenFile, 2) = vbCrLf Then OpenFile = Left(OpenFile, Len(OpenFile) - 2)
Close #1
Kill "tmp"
Select Case OpenFile
Case "yes"
MsgBox "网络没有断开,自动断开!"
Shell "cmd /c ipconfig /release"
Case "no"
MsgBox "网络已断开。", 0
End Select
End Sub
Dim OpenFile, i
CreateObject("wscript.shell").run "cmd /c ping www.baidu.com>nul 2>nul&&echo yes>""tmp""||echo no>""tmp""", 0, 1
Open App.Path & "\tmp" For Input As #1
Do Until EOF(1)
Line Input #1, i
DoEvents
OpenFile = OpenFile & i & NL
Loop
If Right(OpenFile, 2) = vbCrLf Then OpenFile = Left(OpenFile, Len(OpenFile) - 2)
Close #1
Kill "tmp"
Select Case OpenFile
Case "yes"
MsgBox "网络没有断开,自动断开!"
Shell "cmd /c ipconfig /release"
Case "no"
MsgBox "网络已断开。", 0
End Select
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询