Advertisement
Kresha7

Process Protection C#

Apr 14th, 2011
1,546
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.32 KB | None | 0 0
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.Data;
  5. using System.Diagnostics;
  6. using System.Runtime.InteropServices;
  7. public class clsProcessProtect
  8. {
  9.  
  10.     [DllImport("ntdll")]
  11.     private static extern int NtSetInformationProcess(IntPtr hProcess, int processInformationClass, ref int processInformation, int processInformationLength);
  12.  
  13.     EventHandler psStop = new EventHandler(StopProcessProtection);
  14.     const  iStop = 0;
  15.     const  iStart = 1;
  16.     const  ProcessPriorityClass = 29;
  17.     public clsProcessProtect()
  18.     {
  19.     }
  20.  
  21.     public clsProcessProtect()
  22.     {
  23.     }
  24.  
  25.     public void Start()
  26.     {
  27.         StartProcessProtection(ref iStart);
  28.         AppDomain.CurrentDomain.ProcessExit += psStop;
  29.         AppDomain.CurrentDomain.DomainUnload += psStop;
  30.         Application.ApplicationExit += psStop;
  31.     }
  32.  
  33.     private bool StartProcessProtection(ref int psInfo)
  34.     {
  35.         try {
  36.             NtSetInformationProcess(Process.GetCurrentProcess().Handle, ProcessPriorityClass, ref psInfo, Marshal.SizeOf(psInfo));
  37.             return true;
  38.         } catch (Exception ex) {
  39.             MessageBox.Show(ex.Message + Constants.vbNewLine + ex.InnerException.ToString());
  40.         }
  41.  
  42.     }
  43.  
  44.     private bool StopProcessProtection()
  45.     {
  46.         try {
  47.             StartProcessProtection(ref iStop);
  48.         } catch (Exception ex) {
  49.             MessageBox.Show(ex.Message + "\n" + ex.InnerException.ToString());
  50.         }
  51.     }
  52.  
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement