如何防止普通用户终止进程
How to prevent Normal users from terminating process?
如何阻止用户终止进程??
static BOOL WINAPI console_ctrl_handler(DWORD dwCtrlType)
{
switch (dwCtrlType)
{
case CTRL_C_EVENT: // Ctrl+C
{
break;
//return TRUE;
}
case CTRL_BREAK_EVENT: // Ctrl+Break
break;
case CTRL_CLOSE_EVENT: // Closing the console window //event was caught
//But I guess call exitProcess ()
break;
//return TRUE;
case CTRL_LOGOFF_EVENT: // User logs off. Passed only to services!
break;
case CTRL_SHUTDOWN_EVENT: // System is shutting down. Passed only to services!
break;
}
// Return TRUE if handled this message, further handler functions won't be called.
// Return FALSE to pass this message to further handlers until default handler calls ExitProcess().
return TRUE;
}
它是我的SetConsoleCtrlHandler处理器。当我调试CTRL_C_EVENT成功返回true时,它被忽略了。
但CTRL_CLOSE_EVENT也被捕获,返回TRUE但退出
有什么问题吗?
这是我的解决方案,如果处理器捕获CLOSE_WINDOW事件,
然后创建相同的CreateProcess
任何想要和我一样的东西的人,只要把它应用到你的程序中。
BOOL WINAPI console_ctrl_handler(DWORD dwCtrlType){
HANDLE current_process= GetCurrentProcess();//
char filePath[MAX_PATH]="";
DWORD size=MAX_PATH;
QueryFullProcessImageName(current_process,0,filePath,&size);//
STARTUPINFO startupInfo = {0};
startupInfo.cb = sizeof(startupInfo);
PROCESS_INFORMATION processInformation;
switch (dwCtrlType){
case CTRL_C_EVENT: // Ctrl+C
break;
case CTRL_CLOSE_EVENT: // Closing the console window //
//
system("cls");//
CreateProcess(
filePath,
NULL,
NULL,
NULL,
FALSE,
NORMAL_PRIORITY_CLASS,
NULL,
NULL,
&startupInfo,
&processInformation
);
break; //
case CTRL_BREAK_EVENT: // Ctrl+Break
break;
case CTRL_LOGOFF_EVENT: // User logs off. Passed only to services!
break;
case CTRL_SHUTDOWN_EVENT: // System is shutting down. Passed only to services!
break;
}//switch
// Return TRUE if handled this message, further handler functions won't be called.
// Return FALSE to pass this message to further handlers until default handler calls ExitProcess().
return TRUE;
}
把你的程序变成Windows服务[1]。Windows服务在后台运行,所以没有关闭按钮。它们还可以作为另一个用户运行,这样普通用户就不能终止它。
许多服务在高权限下运行。还可以以管理员以外的其他用户运行服务,这可能是需要的。
[1] http://msdn.microsoft.com/en-us/library/windows/desktop/bb540476%28v=vs.85%29.aspx
相关文章:
- 运行代码时,c++ 会终止进程
- CLion 如何终止进程运行?
- 使用进程 ID 终止进程
- 有没有办法通过过滤进程的名称来自动终止进程?
- Windows资源监视器使用哪些Win32函数来检测已终止进程的磁盘和网络活动
- 终止进程并关闭其所有打开的侦听端口
- 如何释放被终止进程锁定的端口
- 使用进程名称终止进程
- 如何检测终止进程事件、计算机关闭和计算机崩溃
- 我无法使用终止进程杀死子进程
- 使用终止进程终止"mstsc.exe"进程时出现错误代码(5)访问被拒绝
- 在跨平台C++启动和终止进程
- 使用SIGSEGV或SIGABRT信号转储核心并终止进程
- 如何使用管理权限调用终止进程
- QT中的运行和终止进程C++通过按下按钮
- 使用SIGHUP重新启动终止进程
- dbus-c++中的断言错误,终止进程
- 如果在堆上定义,QProcess 不会终止/终止进程
- WinAPI - windows关闭前的清理终止进程
- 从VS10应用程序中查找/终止进程(VC6应用程序)