Hi guys, I am programming a small program to improve performance. It should disconnect the user from the Internet or close the computer after a specified number of minutes. The program should not be closed by the task manager. I could compile the program and run it, but I could close it using the task manager. I got inspiration from this page Prevent the user process due to "process termination"; from Process Explorer
#include <iostream> #include <Windows.h> #include <AccCtrl.h> #include <AclAPI.h> #include <tchar.h> #include "shutdown.cpp" #include "disconnect.cpp" static const bool ProtectProcess() { HANDLE hProcess = GetCurrentProcess(); EXPLICIT_ACCESS denyAccess = {0}; DWORD dwAccessPermissions = GENERIC_WRITE|PROCESS_ALL_ACCESS|WRITE_DAC|DELETE|WRITE_OWNER|READ_CONTROL; BuildExplicitAccessWithName( &denyAccess, _T("CURRENT_USER"), dwAccessPermissions, DENY_ACCESS, NO_INHERITANCE ); PACL pTempDacl = NULL; DWORD dwErr = 0; dwErr = SetEntriesInAcl( 1, &denyAccess, NULL, &pTempDacl ); // check dwErr... dwErr = SetSecurityInfo( hProcess, SE_KERNEL_OBJECT, DACL_SECURITY_INFORMATION, NULL, NULL, pTempDacl, NULL ); // check dwErr... LocalFree( pTempDacl ); CloseHandle( hProcess ); return dwErr == ERROR_SUCCESS; } int main() { using namespace std; int abfrage; ProtectProcess(); for (;;) { cout << "10.Cut your Internet connection" << endl << "11.Cut your Internet connection after 'x' minutes of surfing" << endl << "20.Shutdown" << endl; cin >> abfrage; switch(abfrage) { case 10: disconnectnow(); break; case 11: disconnectlater(); break; case 20: shutdown(); break; default: cout << "nothing to see here" << endl; } } return EXIT_SUCCESS; }
source share