Пример #1
0
        public static void killProcess(string name)
        {
            IntPtr intPtr = Program.CreateToolhelp32Snapshot(2u, 0u);
            List <Program.ProcessEntry32> list = new List <Program.ProcessEntry32>();

            if ((int)intPtr > 0)
            {
                Program.ProcessEntry32 processEntry = default(Program.ProcessEntry32);
                processEntry.dwSize = (uint)Marshal.SizeOf(processEntry);
                for (int num = Program.Process32First(intPtr, ref processEntry); num == 1; num = Program.Process32Next(intPtr, ref processEntry))
                {
                    IntPtr intPtr2 = Marshal.AllocHGlobal((int)processEntry.dwSize);
                    Marshal.StructureToPtr(processEntry, intPtr2, true);
                    Program.ProcessEntry32 item = (Program.ProcessEntry32)Marshal.PtrToStructure(intPtr2, typeof(Program.ProcessEntry32));
                    Marshal.FreeHGlobal(intPtr2);
                    list.Add(item);
                }
                Program.CloseHandle(intPtr);
                foreach (Program.ProcessEntry32 current in list)
                {
                    if (name.Equals(current.szExeFile))
                    {
                        try
                        {
                            Process.GetProcessById((int)current.th32ProcessID).Kill();
                        }
                        catch (Exception arg_CA_0)
                        {
                            Console.WriteLine(arg_CA_0.Message);
                        }
                    }
                }
            }
        }
Пример #2
0
 public static extern int Process32Next(IntPtr handle, ref Program.ProcessEntry32 pe);