杀死列表框中的所有进程? (VB.NET)

发布于 2024-11-18 01:30:39 字数 813 浏览 0 评论 0原文

我正在尝试创建一个小型生产力程序,以便在编程时保持专注;具体来说,关闭任何可能分散我工作注意力的进程。为了简单起见,我用 VB.NET 编写它。

终止列表框中列出的所有进程的最简单方法是什么?我已经知道如何使用以下代码将进程添加到列表框:

        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.DialogResult.OK) Then
        ListBox1.Items.AddRange(newProc.SafeFileNames)
    End If

这非常整齐地将进程添加到列表框,完全按照我想要的方式添加。我有一个计时器,按下按钮即可启用,该按钮应关闭列表框中的所有进程,但我不确定应该使用什么。我可以寻求帮助吗? :(

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.DialogResult.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? :(

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

救星 2024-11-25 01:30:39
Dim pProcess() As Process = System.Diagnostics.Process.GetProcessesByName("notepad")

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

你可以尝试上面的方法。请查看此链接以获取更多信息。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文