嗨,大家好我正在编写一个小程序,以提高生产力。它应该断开用户与Internet的连接,或者在预设的分钟数后关闭计算机。该程序不应该与任务管理器关闭。我可以编译程序并运行,但我可以用任务管理器关闭它。我得到了我的灵感来自于这个页面 Prevent user process from being killed with "End Process" 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;
}
管理员将*总是*能够杀死你的程序,不是吗?并不会停止互联网连接,使您*少*生产力? – 2012-03-17 22:38:29
从任务管理器隐藏程序或防止它们被关闭是Windows出于显而易见的原因难以预防的原因。 – ChrisF 2012-03-17 22:39:01
@Carl Norum我经常需要阅读pdf才能学习,但互联网让我无法读书。它既不能与管理员也不能使用用户权限。 – AaronP 2012-03-17 22:50:52