我正在尝试创建一个小型的生产力计划,以便在编程时保持专注;特别是,关闭任何可能分散我工作注意力的过程。为简单起见,我在VB.NET中编写它。
杀死listBox中列出的所有进程的最简单方法是什么?我已经知道如何使用以下代码将进程添加到我的listBox:
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
这会非常巧妙地将进程添加到listBox中,这完全是我想要的。我有一个计时器,通过按下一个应该关闭listBox中所有进程的按钮来启用,但我不确定我应该使用什么。我可以得到一些帮助吗? :(
答案 0 :(得分:0)
Dim pProcess() As Process = System.Diagnostics.Process.GetProcessesByName("notepad")
For Each p As Process In pProcess
p.Kill()
Next
您可以尝试以上方法。请查看此link以获取更多信息。