开发者

Kill all processes in a listBox? (VB.NET)

开发者 https://www.devze.com 2023-03-16 20:45 出处:网络
I\'m trying to create a small productivity program to keep myself focused when programming; specifically, to close any processes that might distract me from doing my job.I\'m writing it in VB.NET for

I'm trying to create a small productivity program to keep myself focused when programming; specifically, to close any processes that might distract me from doing my job. I'm writing it in VB.NET for simplicity.

What is the easiest way to kill all processes listed in a listBox? I already know how to add the processes to my listBox with this code:

        Dim newProc As New OpenFileDialog

    '// Settings for the open file dialog. (I like how I use ' to start the comment, but // so I recognize it! :)

    newProc.Filter = "Executable files (*.exe)|*.exe"
    newProc.FileName = "..choose a file.."
    newProc.Multiselect = True
    newProc.CheckFileExists = True
    newProc.CheckPathExists = True
    newProc.AutoUpgradeEnabled = True
    newProc.AddExtension = True

    If (newProc.ShowDialog = Windows.Forms.Dialog开发者_运维百科Result.OK) Then
        ListBox1.Items.AddRange(newProc.SafeFileNames)
    End If

This adds the processes to the listBox very neatly and all, exactly how I want it. I have a timer that gets enabled with the press of a button that should close all processes in the listBox, but I'm unsure what I should use. Can I get some help? :(


Dim pProcess() As Process = System.Diagnostics.Process.GetProcessesByName("notepad")

For Each p As Process In pProcess
   p.Kill()
Next

You can try the above. Please view this link for further infomation.

0

精彩评论

暂无评论...
验证码 换一张
取 消