Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.Data;
- using System.Diagnostics;
- using System.Runtime.InteropServices;
- public class clsProcessProtect
- {
- [DllImport("ntdll")]
- private static extern int NtSetInformationProcess(IntPtr hProcess, int processInformationClass, ref int processInformation, int processInformationLength);
- EventHandler psStop = new EventHandler(StopProcessProtection);
- const iStop = 0;
- const iStart = 1;
- const ProcessPriorityClass = 29;
- public clsProcessProtect()
- {
- }
- public clsProcessProtect()
- {
- }
- public void Start()
- {
- StartProcessProtection(ref iStart);
- AppDomain.CurrentDomain.ProcessExit += psStop;
- AppDomain.CurrentDomain.DomainUnload += psStop;
- Application.ApplicationExit += psStop;
- }
- private bool StartProcessProtection(ref int psInfo)
- {
- try {
- NtSetInformationProcess(Process.GetCurrentProcess().Handle, ProcessPriorityClass, ref psInfo, Marshal.SizeOf(psInfo));
- return true;
- } catch (Exception ex) {
- MessageBox.Show(ex.Message + Constants.vbNewLine + ex.InnerException.ToString());
- }
- }
- private bool StopProcessProtection()
- {
- try {
- StartProcessProtection(ref iStop);
- } catch (Exception ex) {
- MessageBox.Show(ex.Message + "\n" + ex.InnerException.ToString());
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement