推荐文章

c#去除字符串中的空格,回车,换行符,制表符

c#去除字符串中的空格,回车,换行符,制表符

c#去除字符串中的空格,回车,换行符,制表符
C#监控程序启动和关闭

C#监控程序启动和关闭

C#监控程序启动和关闭using System;using System.Collections.Generic;using System.Text;using System.Diagnostics;using System.Threading;namespace ProcessListener{ class Program { static void Main(stri
C#操作USB口的摄像头

C#操作USB口的摄像头

private const uint BM_CLICK = 0xF5; 鼠标点击的消息,对于各种消息的数值,查API手册,也可用VS2010自带的SPY++ [DllImpt("user32.dll", EntryPoint = "SendMessage", SetLastErr = true, Set = Set.Auto)]private static extern int SendMe
C# FTP操作

C# FTP操作

C# FTP操作
C#文件监控对象FileSystemWatcher

C#文件监控对象FileSystemWatcher

使用C#文件监控对象FileSystemWatcher对文件夹下的删除、修改、新增

C#监控程序启动和关闭

日期:2018-07-04 点击:923 来源:PB2.CN

C#监控程序启动和关闭

using System;

using System.Collections.Generic;
using System.Text;
using System.Diagnostics;
using System.Threading;
namespace ProcessListener
{
    class Program
    {
        static void Main(string[] args)
        {
            for (; ; )
            {
                bool isNotePadStart = false;//标识记事本进程是否启动
                bool isExplorerStart = false;//标识explorer进程是否启动
                Process[] processes = Process.GetProcesses();//获取所有进程信息
                for (int i = 0; i < processes.Length; i++)
                {
                    if (processes[i].ProcessName.ToLower() == "notepad")
                    {
                        Console.WriteLine("找到记事本进程!即将关闭explorer进程");
                        // Thread.Sleep(1000);
                        isNotePadStart = true;
                        for (int j = 0; j < processes.Length; j++)
                        {
                            if (processes[j].ProcessName.ToLower() == "explorer")
                            {
                                try
                                {
                                    processes[j].Kill();
                                }
                                catch (Exception)
                                {
                                    Console.WriteLine("进程访问失败!");
                                }
                                Console.WriteLine("已关闭explorer.exe!");
                            }
                        }
                    }
                    if (processes[i].ProcessName.ToLower() == "explorer")
                    {
                        isExplorerStart = true;
                    }
                }
                if (!isNotePadStart && !isExplorerStart)
                {
                    Process.Start("explorer.exe");
                    isNotePadStart = true;
                }
            }
        }
    }
}


这篇文档对您是否有帮助?

c#去除字符串中的空格,回车,换行符,制表符

c#去除字符串中的空格,回车,换行符,制表符

c#去除字符串中的空格,回车,换行符,制表符
C#监控程序启动和关闭

C#监控程序启动和关闭

C#监控程序启动和关闭using System;using System.Collections.Generic;using System.Text;using System.Diagnostics;using System.Threading;namespace ProcessListener{ class Program { static void Main(stri
C#操作USB口的摄像头

C#操作USB口的摄像头

private const uint BM_CLICK = 0xF5; 鼠标点击的消息,对于各种消息的数值,查API手册,也可用VS2010自带的SPY++ [DllImpt("user32.dll", EntryPoint = "SendMessage", SetLastErr = true, Set = Set.Auto)]private static extern int SendMe
C# FTP操作

C# FTP操作

C# FTP操作
C#文件监控对象FileSystemWatcher

C#文件监控对象FileSystemWatcher

使用C#文件监控对象FileSystemWatcher对文件夹下的删除、修改、新增