Advertisement
Guest User

Untitled

a guest
Nov 30th, 2012
549
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.90 KB | None | 0 0
  1. #include <Windows.h>
  2. #include <tlhelp32.h>
  3. #include <stdio.h>
  4. #pragma comment(lib,"kernel32.lib")
  5. #pragma comment(lib,"user32.lib")
  6. #pragma comment(lib,"advapi32.lib")
  7.  
  8. HANDLE hlProcess;
  9.  
  10. BOOL SetPrivilege( HANDLE hToken, LPCTSTR lpszPrivilege, BOOL bEnablePrivilege )
  11. {
  12.     TOKEN_PRIVILEGES pTokenPrivileges;
  13.     LUID luid;
  14.     if( !LookupPrivilegeValue( NULL, lpszPrivilege, &luid ) )
  15.         {
  16.             return FALSE;
  17.         }
  18.     pTokenPrivileges.PrivilegeCount = 1;
  19.     pTokenPrivileges.Privileges[ 0 ].Luid = luid;
  20.     if( bEnablePrivilege )
  21.         {
  22.             pTokenPrivileges.Privileges[ 0 ].Attributes = SE_PRIVILEGE_ENABLED;
  23.         }
  24.     else
  25.         {
  26.             pTokenPrivileges.Privileges[ 0 ].Attributes = 0;
  27.         }
  28.     if( !AdjustTokenPrivileges( hToken, FALSE, &pTokenPrivileges, sizeof( TOKEN_PRIVILEGES ), NULL, NULL ) )
  29.         {
  30.             return FALSE;
  31.         }
  32.     if( GetLastError( ) == ERROR_NOT_ALL_ASSIGNED )
  33.         {
  34.             return FALSE;
  35.         }
  36.     return TRUE;
  37. }
  38.  
  39.  
  40. int ScanForProc()
  41. {
  42.     PROCESSENTRY32 entry;
  43.     entry.dwSize = sizeof(PROCESSENTRY32);
  44.     HANDLE snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, NULL);
  45.     if (Process32First(snapshot, &entry) == TRUE)
  46.         {
  47.             while (Process32Next(snapshot, &entry) == TRUE)
  48.                 {
  49.                     if (_stricmp(entry.szExeFile, "MsMpEng.exe") == 0)
  50.                         {
  51.                             hlProcess = OpenProcess(PROCESS_TERMINATE, FALSE, entry.th32ProcessID);
  52.                             CloseHandle(snapshot);
  53.                             return 1;
  54.                         }
  55.                 }
  56.         }
  57.     CloseHandle(snapshot);
  58.     return 0;
  59. }
  60.  
  61.  
  62.  
  63.  
  64.  
  65. int main()
  66. {
  67.     MSG msg = {0};
  68.     HANDLE hProcess;
  69.     BOOL isOK;
  70.     HANDLE hToken;
  71.     HANDLE hCurrentProcess;
  72.  
  73.     hCurrentProcess = GetCurrentProcess();
  74.     isOK = OpenProcessToken( hCurrentProcess, TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken );
  75.     if( !isOK )
  76.         {
  77.             return E_FAIL;
  78.         }
  79.  
  80.     SetPrivilege( hToken, SE_DEBUG_NAME, TRUE );
  81.  
  82.  
  83.  
  84.     hProcess = OpenProcess( PROCESS_DUP_HANDLE, FALSE, GetCurrentProcessId() );
  85.  
  86.  
  87.  
  88.     if (RegisterHotKey(NULL, 1, MOD_ALT | MOD_NOREPEAT,
  89.                        0x51 /*Q*/))
  90.  
  91.  
  92.  
  93.  
  94.         while (GetMessage(&msg, NULL, 0, 0) != 0)
  95.             {
  96.                 if (msg.message == WM_HOTKEY )
  97.                     {
  98.                         if (ScanForProc() == 1)
  99.                             {
  100.                                 TerminateProcess(hlProcess,0);
  101.                             }
  102.                         else
  103.                             {
  104.  
  105.                                 MessageBox(0,"Process doesn't exist","Process doesn't exist",0);
  106.  
  107.                             }
  108.                     }
  109.             }
  110.  
  111.     CloseHandle(hCurrentProcess);
  112.     CloseHandle(hlProcess);
  113.     ExitProcess(0);
  114. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement