Esempio n. 1
0
        /// <summary>
        /// Close process if it's opened
        /// </summary>
        /// <param name="file">The ID of the process you are trying to close</param>
        public static void KillProcess(FileInfo file)
        {
            var args = new WindowsEventArgs();

            args.File = file;
            var process = GetProcess(file);

            KillProcess(process, args);
        }
Esempio n. 2
0
        /// <summary>
        /// Close process if it's opened
        /// </summary>
        /// <param name="procID">The ID of the process you are trying to close</param>
        public static void KillProcess(int procID)
        {
            var args = new WindowsEventArgs();

            args.ProcessID = procID;
            var process = GetProcess(procID);

            KillProcess(process, args);
        }
Esempio n. 3
0
        /// <summary>
        /// Fires when a process failed to close
        /// </summary>
        /// <param name="e">args containing the name of the process that failed to close</param>
        public void OnFailedToCloseProc(WindowsEventArgs e)
        {
            EventHandler <WindowsEventArgs> handler = FailedToCloseProc;

            if (handler != null)
            {
                handler(this, e);
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Fire when a process has been closed
        /// </summary>
        /// <param name="e">args containing the name of the process that was closed</param>
        public void OnProcessClosed(WindowsEventArgs e)
        {
            EventHandler <WindowsEventArgs> handler = ProcessClosed;

            if (handler != null)
            {
                handler(this, e);
            }
        }
Esempio n. 5
0
        /// <summary>
        /// Close process if it's opened
        /// </summary>
        /// <param name="process">Process to close</param>
        /// <param name="args">Event args that are called if the process closes successfully or fails</param>
        public static void KillProcess(Process process, WindowsEventArgs args = null)
        {
            if (process == null)
            {
                new Utility().OnFailedToCloseProc(args);
                return;
            }

            process.Kill();
            new Utility().OnProcessClosed(args);
        }
Esempio n. 6
0
        /// <summary>
        /// Close process if it's opened
        /// </summary>
        /// <param name="name">ProcName or WindowTitle of the process to close.
        /// ProcName is the same as the exe name without the ".exe". WindowTitle is the title of the window</param>
        /// <param name="type">Which part of the process are you looking for, to find and close process</param>
        public static void KillProcess(string name, ProcType type = ProcType.ProcessName)
        {
            var args    = new WindowsEventArgs();
            var process = GetProcess(name, type);

            if (type == ProcType.ProcessName)
            {
                args.ProcessName = name;
            }
            else
            {
                args.ProcessWindowTitle = name;
            }

            KillProcess(process, args);
        }