【发布时间】:2020-01-23 05:29:57
【问题描述】:
我想要一个代码,当用户的互联网连接被禁用时,关闭 chrome.exe
正如你在下面看到的那样。
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
Dim ip = "www.google.com"
Dim timeout = 1000
Dim sw = New Stopwatch()
myProcesses = Process.GetProcessesByName("chrome")
Try
Dim ping As Long = -1
sw.Start()
If My.Computer.Network.Ping(ip, timeout) Then
sw.Stop()
ping = sw.ElapsedMilliseconds
For Each myProcess In myProcesses
If myProcess IsNot Nothing Then
myProcess.Kill()
MessageBox.Show("Internet down")
Me.Close()
End If
Next
End If
If ping < 500 Then
Else
End If
Catch ex As Exception
Console.WriteLine(ex.ToString())
End Try
End Sub
你能帮我解决这个问题吗?我还启用了 Timer1,所以我认为它应该可以正常工作。
感谢大家的帮助,对于此类小问题,很抱歉耽误您的时间。
【问题讨论】:
-
Ping()方法返回真或假取决于地址是否可以被 ping 通。看来您需要在它前面加上Not。 -
你的意思是这样吗?
If My.Computer.Network.Ping(ip, Not timeout) Then -
您好 Aybe,不幸的是,该链接中没有对 Visual Basic 的解释,我是一名新开发人员,这就是为什么我无法找到它的原因 :( :( 对不起