反JC锁屏
zhangshuhang2011 · · 个人记录
#include<bits/stdc++.h>
#include<windows.h>
#include<conio.h>
using namespace std;
//link: http://zhidao.baidu.com/question/141926361388407565/answer/3209412938
void full_screen(){
HWND hwnd = GetForegroundWindow();
int cx = GetSystemMetrics(SM_CXSCREEN);
int cy = GetSystemMetrics(SM_CYSCREEN);
LONG l_WinStyle = GetWindowLong(hwnd,GWL_STYLE);
SetWindowLong(hwnd,GWL_STYLE,(l_WinStyle | WS_POPUP | WS_MAXIMIZE) & ~WS_CAPTION & ~WS_THICKFRAME & ~WS_BORDER);
SetWindowPos(hwnd, HWND_TOP, 0, 0, cx, cy, 0);
}
//link: https://blog.csdn.net/weixin_45888599/article/details/112612468
bool IsProcessRunAsAdmin()
{
SID_IDENTIFIER_AUTHORITY NtAuthority = SECURITY_NT_AUTHORITY;
PSID AdministratorsGroup;
BOOL b = AllocateAndInitializeSid(
&NtAuthority,
2,
SECURITY_BUILTIN_DOMAIN_RID,
DOMAIN_ALIAS_RID_ADMINS,
0, 0, 0, 0, 0, 0,
&AdministratorsGroup);
if(b)
{
CheckTokenMembership(NULL, AdministratorsGroup, &b);
FreeSid(AdministratorsGroup);
}
return b == TRUE;
}
bool AdminOk;
short GetAdmin(LPCSTR Param, int Showcmd)
{
if (IsProcessRunAsAdmin()){
AdminOk=true;
return 0;
}
TCHAR Path[MAX_PATH];
ZeroMemory(Path, MAX_PATH);
::GetModuleFileName(NULL, Path, MAX_PATH);
HINSTANCE res;
res = ShellExecute(NULL, "runas", Path, Param, NULL, Showcmd);
if((unsigned long long)res > 32)
return 1;
else{
AdminOk=false;
return 0;
}
}
//mycode
bool EscToQuit;
string getpwd(){
string pwd;
while(true){
char ch = getch();
if('0' <= ch && ch <= '9'){
putch('.');
pwd.push_back(ch);
}else if(ch == '\r'){
putch('\n');
break;
}else if(ch == '\b' && pwd.length() > 0){
putch('\b');
putch(' ');
putch('\b');
pwd.pop_back();
}else if(ch == 27 && EscToQuit){
exit(0);
}
}
return pwd;
}
bool kill;
void killtaskmgr(){
if(!AdminOk) return;
while(kill){
system("taskkill -f -im taskmgr.exe>nul 2>nul");
Sleep(100);
}
}
int main(){
bool succ = GetAdmin("", 1);
if(succ==1) return 0;
full_screen();
EscToQuit = true;
tk1:;
cout << "please enter your password(numeric): ";
string pwd1 = getpwd();
cout << "please enter your password again: ";
string pwd2 = getpwd();
if(pwd2 != pwd1){
cout << "wrong password!" << endl;
Sleep(1000);
system("clear");
goto tk1;
}
EscToQuit = false;
kill = true;
thread myThread(killtaskmgr);
cout << "the password is ok." << endl;
Sleep(1000);
system("clear");
while(true){
cout << "please enter the password: ";
string pwd3 = getpwd();
if(pwd3 == pwd1) break;
cout << "wrong password!" << endl;
Sleep(1000);
system("clear");
}
kill = false;
myThread.join();
return 0;
}
C++编写,可以禁止任务管理器
使用方法:
- 上锁:设置密码
\rightarrow 确认密码 - 解锁:输入密码
\rightarrow 上锁成功
设置/确认密码过程中按Esc可以退出,锁定期间无法打开任务管理器(当然前提是有管理员权限)。