Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Diagnostics;
- using System.Runtime.InteropServices;
- static class Program
- {
- [DllImport("user32.dll")]
- [return: MarshalAs(UnmanagedType.Bool)]
- static extern bool IsWindowVisible(IntPtr hWnd);
- public static bool IsProcessDead(Process pr)
- {
- IntPtr hwnd = pr.MainWindowHandle;
- if (hwnd == IntPtr.Zero) return true;
- return !IsWindowVisible(hwnd);
- }
- void ClearProcesses()
- {
- Process[] prs=Process.GetProcessesByName("excel");
- foreach (Process proc in prs)
- {
- if(IsProcessDead(proc))proc.Kill();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement