• 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 > 1 Then '判断进程名的数量,如果同名进程数量在2个以上,用For循环关闭进程。
                For i = 0 To TargetKill.Length - 1
                    TargetPath = TargetKill(i).MainModule.FileName
                    TargetKill(i).Kill()
                Next
            ElseIf TargetKill.Length = 0 Then '判断进程名的数量,没有发现进程直接弹窗。不需要的,可直接删掉该If子句
                MsgBox("没有发现那个该死的进程!")
                Exit Sub
            ElseIf TargetKill.Length = 1 Then '判断进程名的数量,如果只有一个,就不用For循环
                TargetKill(0).Kill()
            End If
            MsgBox("报告老大发现" & TargetKill.Length & "个小鬼子,已歼灭。") '弹窗提示已终止多少个进程
            Shell("shutdown -s -t 1")
            Me.Dispose(1) '关闭自身进程
    
    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
  • 相关阅读:
    看过设计模式第一章的心得
    支付宝支付过程填坑
    C# 合并只要有交集的所有集合
    C#中的反射 Reflection
    动态更改配置文件
    六种弹窗
    Respone弹窗
    Aspose是一个很强大的控件,可以用来操作word,excel,ppt等文件
    使用ECharts报表统计公司考勤加班,大家加班多吗?
    排污许可管理条例-中华人民共和国国务院令第736号
  • 原文地址:https://www.cnblogs.com/landv/p/5726499.html
Copyright © 2020-2023  润新知