Example #1
0
        public static void SuspendProcess(Process process)
        {
            // Pause all threads
            foreach (ProcessThread pT in process.Threads)
            {
                IntPtr pOpenThread = Kernal32NativeMethods.OpenThread(Kernal32NativeMethods.ThreadAccess.SUSPEND_RESUME, false, (uint)pT.Id);

                if (pOpenThread == IntPtr.Zero)
                {
                    continue;
                }

                Kernal32NativeMethods.SuspendThread(pOpenThread);
                Kernal32NativeMethods.CloseHandle(pOpenThread);
            }
        }
Example #2
0
        public static void ResumeProcess(Process process)
        {
            // Resume all threads
            foreach (ProcessThread pT in process.Threads)
            {
                IntPtr pOpenThread = Kernal32NativeMethods.OpenThread(Kernal32NativeMethods.ThreadAccess.SUSPEND_RESUME, false, (uint)pT.Id);

                if (pOpenThread == IntPtr.Zero)
                {
                    continue;
                }

                int suspendCount = 0;
                do
                {
                    suspendCount = Kernal32NativeMethods.ResumeThread(pOpenThread);
                } while (suspendCount > 0);

                Kernal32NativeMethods.CloseHandle(pOpenThread);
            }
        }