因为最近上班会打开比较多的软件,导致下班的时候关闭软件也会花费比较多的时间,于是打算写一个关闭所有运行程序的程序。
这就会运用到System.Diagnostics命名空间下的Process类,但是只是涉及到进程的获取和退出,我们不需要了解太多,记住几个关键的属性:Id, ProcessName,MainWindowHandle,还有Kill方法,基本上够用。
MainWindowHandle作为一个关键属性,可以区分系统后台进程和用户运行的普通程序。
以下是窗体脚本代码,MainWindow.xaml:
<Window x:Class="KillProcess.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:KillProcess"
mc:Ignorable="d"
Title="KillProcess" Height="350" Width="525"&g