Advertisement
Kresha7

Process Protection VB.NET

Apr 14th, 2011
2,394
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 1.45 KB | None | 0 0
  1. Imports System.Runtime.InteropServices
  2. Public Class clsProcessProtect
  3.  
  4.     <DllImport("ntdll")> _
  5. Private Shared Function NtSetInformationProcess(ByVal hProcess As IntPtr, ByVal processInformationClass As Integer, ByRef processInformation As Integer, ByVal processInformationLength As Integer) As Integer
  6.     End Function
  7.  
  8.     Dim psStop As New EventHandler(AddressOf StopProcessProtection)
  9.     Const iStop = 0
  10.     Const iStart = 1
  11.     Const ProcessPriorityClass = 29
  12.     Public Sub New()
  13.     End Sub
  14.  
  15.  Public Sub New()
  16.  End Sub
  17.  
  18.     Public Sub Start()
  19.         StartProcessProtection(iStart)
  20.         AddHandler AppDomain.CurrentDomain.ProcessExit, psStop
  21.         AddHandler AppDomain.CurrentDomain.DomainUnload, psStop
  22.         AddHandler Application.ApplicationExit, psStop
  23.     End Sub
  24.  
  25.     Private Function StartProcessProtection(ByRef psInfo As Integer) As Boolean
  26.         Try
  27.             NtSetInformationProcess(Process.GetCurrentProcess().Handle, ProcessPriorityClass, psInfo, Marshal.SizeOf(psInfo))
  28.             Return True
  29.         Catch ex As Exception
  30.             MessageBox.Show(ex.Message & vbNewLine & ex.InnerException.ToString())
  31.         End Try
  32.  
  33.     End Function
  34.  
  35.     Private Function StopProcessProtection() As Boolean
  36.         Try
  37.             StartProcessProtection(iStop)
  38.         Catch ex As Exception
  39.             MessageBox.Show(ex.Message & vbNewLine & ex.InnerException.ToString())
  40.         End Try
  41.     End Function
  42.  
  43. End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement