Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Windows.h>
- #include <tlhelp32.h>
- #include <stdio.h>
- #pragma comment(lib,"kernel32.lib")
- #pragma comment(lib,"user32.lib")
- #pragma comment(lib,"advapi32.lib")
- HANDLE hlProcess;
- BOOL SetPrivilege( HANDLE hToken, LPCTSTR lpszPrivilege, BOOL bEnablePrivilege )
- {
- TOKEN_PRIVILEGES pTokenPrivileges;
- LUID luid;
- if( !LookupPrivilegeValue( NULL, lpszPrivilege, &luid ) )
- {
- return FALSE;
- }
- pTokenPrivileges.PrivilegeCount = 1;
- pTokenPrivileges.Privileges[ 0 ].Luid = luid;
- if( bEnablePrivilege )
- {
- pTokenPrivileges.Privileges[ 0 ].Attributes = SE_PRIVILEGE_ENABLED;
- }
- else
- {
- pTokenPrivileges.Privileges[ 0 ].Attributes = 0;
- }
- if( !AdjustTokenPrivileges( hToken, FALSE, &pTokenPrivileges, sizeof( TOKEN_PRIVILEGES ), NULL, NULL ) )
- {
- return FALSE;
- }
- if( GetLastError( ) == ERROR_NOT_ALL_ASSIGNED )
- {
- return FALSE;
- }
- return TRUE;
- }
- int ScanForProc()
- {
- PROCESSENTRY32 entry;
- entry.dwSize = sizeof(PROCESSENTRY32);
- HANDLE snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, NULL);
- if (Process32First(snapshot, &entry) == TRUE)
- {
- while (Process32Next(snapshot, &entry) == TRUE)
- {
- if (_stricmp(entry.szExeFile, "MsMpEng.exe") == 0)
- {
- hlProcess = OpenProcess(PROCESS_TERMINATE, FALSE, entry.th32ProcessID);
- CloseHandle(snapshot);
- return 1;
- }
- }
- }
- CloseHandle(snapshot);
- return 0;
- }
- int main()
- {
- MSG msg = {0};
- HANDLE hProcess;
- BOOL isOK;
- HANDLE hToken;
- HANDLE hCurrentProcess;
- hCurrentProcess = GetCurrentProcess();
- isOK = OpenProcessToken( hCurrentProcess, TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken );
- if( !isOK )
- {
- return E_FAIL;
- }
- SetPrivilege( hToken, SE_DEBUG_NAME, TRUE );
- hProcess = OpenProcess( PROCESS_DUP_HANDLE, FALSE, GetCurrentProcessId() );
- if (RegisterHotKey(NULL, 1, MOD_ALT | MOD_NOREPEAT,
- 0x51 /*Q*/))
- while (GetMessage(&msg, NULL, 0, 0) != 0)
- {
- if (msg.message == WM_HOTKEY )
- {
- if (ScanForProc() == 1)
- {
- TerminateProcess(hlProcess,0);
- }
- else
- {
- MessageBox(0,"Process doesn't exist","Process doesn't exist",0);
- }
- }
- }
- CloseHandle(hCurrentProcess);
- CloseHandle(hlProcess);
- ExitProcess(0);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement