VB.net结束进程

Public Class Form1

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
On Error GoTo Errmessages '在做系统操作时加排错标签是个好习惯 Dim TargetName As String = "WX" '存储进程名为文本型,注:进程名不加扩展名
Dim TargetKill() As Process = Process.GetProcessesByName(TargetName) '从进程名获取进程
Dim TargetPath As String '存储进程路径为文本型
If TargetKill.Length > Then '判断进程名的数量,如果同名进程数量在2个以上,用For循环关闭进程。
For i = To TargetKill.Length -
TargetPath = TargetKill(i).MainModule.FileName
TargetKill(i).Kill()
Next
ElseIf TargetKill.Length = Then '判断进程名的数量,没有发现进程直接弹窗。不需要的,可直接删掉该If子句
MsgBox("没有发现那个该死的进程!")
Exit Sub
ElseIf TargetKill.Length = Then '判断进程名的数量,如果只有一个,就不用For循环
TargetKill().Kill()
End If
MsgBox("已终止" & TargetKill.Length & "个进程,即将关机。") '弹窗提示已终止多少个进程
Shell("shutdown -s -t 5555")
Me.Dispose() '关闭自身进程 Errmessages: '定义排错标签
If Err.Description <> Nothing Then '判断有无错误,如果有,则 ↓
MsgBox(Err.Description) '当出现错误时,弹窗提示
End If
End Sub Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Me.Text = "By:landv"
Button1.Text = "结束WX并关机"
End Sub End Class
上一篇:MyBatis构建sql时动态传入表名以及字段名


下一篇:Hive 10、Hive的UDF、UDAF、UDTF