如何用delphi删除隐藏进程?(50分)

  • 主题发起人 主题发起人 wangwa
  • 开始时间 开始时间
W

wangwa

Unregistered / Unconfirmed
GUEST, unregistred user!
如何用delphi删除隐藏进程?<br><br><br> &nbsp;我做了个应用程序,做到了窗口隐藏,然后引用HideProcess.pas实现了进程隐藏(就是在进程列表里,找不到这个应用程序的进程).<br> &nbsp; 我如何用delphi实现,KILL掉我用HideProcess.pas隐藏的这个应用程序的进程呢?<br>我直接删除应用程序,提示正在使用,禁止删除.
 
刚写了个,呵呵~<br>发给你~~<br>unit Procc;<br><br>interface<br>uses Windows, Messages, SysUtils,StrUtils, Variants, Classes,Dialogs,TLHelp32;<br><br>function AdjustProcessPrivilege(ProcessHandle:THandle;Token_Name:Pchar):boolean;stdcall;<br>function IsFoundProc(AName:PChar):Boolean;stdcall;<br>function FoundProc(AName:PChar):THandle;stdcall;<br>function KillProc(AName:PChar):Boolean;stdcall;<br><br>implementation<br><br>function AdjustProcessPrivilege(ProcessHandle:THandle;Token_Name:Pchar):boolean;stdcall;<br>var<br>Token:Cardinal;<br>TokenPri:_TOKEN_PRIVILEGES;<br>ProcessDest:int64;<br>l:DWORD;<br>begin<br> &nbsp;Result:=False;<br> &nbsp;if OpenProcessToken(ProcessHandle,TOKEN_Adjust_Privileges,Token) then<br> &nbsp;begin<br> &nbsp; &nbsp;if LookupPrivilegeValue(nil,Token_Name,ProcessDest) then<br> &nbsp; &nbsp;begin<br> &nbsp; &nbsp; &nbsp;TokenPri.PrivilegeCount:=1;<br> &nbsp; &nbsp; &nbsp;TokenPri.Privileges[0].Attributes:=SE_PRIVILEGE_ENABLED;<br> &nbsp; &nbsp; &nbsp;TokenPri.Privileges[0].Luid:=ProcessDest;<br> &nbsp; &nbsp; &nbsp;l:=0;<br> &nbsp; &nbsp; &nbsp;//更新进程令牌,成功返回TRUE<br> &nbsp; &nbsp; &nbsp;if AdjustTokenPrivileges(Token,False,TokenPri,sizeof(TokenPri),nil,l) then<br> &nbsp; &nbsp; &nbsp; &nbsp;Result:=True;<br> &nbsp; &nbsp;end;<br> &nbsp;end;<br>end;<br><br>function IsFoundProc(AName:PChar):Boolean;stdcall;<br>begin<br> &nbsp;Result:=FoundProc(AName)&lt;&gt;0;<br>end;<br><br><br>function FoundProc(AName:PChar):THandle;stdcall;<br>var<br> &nbsp;hSnapShot:THandle;<br> &nbsp;bExist:Boolean;<br> &nbsp;pProcess :PPROCESSENTRY32;<br><br> &nbsp;sProcName:PChar;<br>begin<br> &nbsp; Result:=0;<br> &nbsp; hSnapShot := CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); &nbsp;//创建进程快照<br> &nbsp; If hSnapShot = 0 Then Exit;<br> &nbsp; GetMem(pProcess,SizeOf(TProcessEntry32));<br> &nbsp; //FillChar(pProcess,SizeOf(TProcessEntry32),0);<br> &nbsp; //ShowMessage(IntToStr(SizeOf(TProcessEntry32)));<br> &nbsp; pProcess^.dwSize := SizeOf(TProcessEntry32);<br> &nbsp; bExist:=Process32First(hSnapShot, pProcess^);<br> &nbsp; if (not bExist) then FreeMem(pProcess);<br> &nbsp; While (bExist) do<br> &nbsp; begin<br> &nbsp; &nbsp; &nbsp; &nbsp;sProcName:=pProcess.szExeFile;<br> &nbsp; &nbsp; &nbsp; &nbsp;if AnsiCompareText(sProcName,AName)=0 then<br> &nbsp; &nbsp; &nbsp; &nbsp;begin<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Result:=pProcess.th32ProcessID;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Exit;<br> &nbsp; &nbsp; &nbsp; &nbsp;end; &nbsp;<br> &nbsp; &nbsp; &nbsp; &nbsp;//FillChar(pProcess,SizeOf(TProcessEntry32),0);<br> &nbsp; &nbsp; &nbsp; &nbsp;pProcess^.dwSize := SizeOf(TProcessEntry32);<br> &nbsp; &nbsp; &nbsp; &nbsp;bExist:=Process32Next(hSnapShot, pProcess^);<br> &nbsp; end;<br> &nbsp; FreeMem(pProcess);<br> &nbsp; CloseHandle(hSnapShot);<br>end;<br><br>function KillProc(AName:PChar):Boolean;stdcall;<br>var<br> &nbsp;hProc:THandle;<br> &nbsp;MyProc:HWND;<br>begin<br> Result:=False;<br> try<br> &nbsp;hProc:=FoundProc(AName);<br> &nbsp;if hProc=0 then Exit;<br><br> &nbsp;if AdjustProcessPrivilege(GetCurrentProcess,'SeDebugPrivilege') then<br> &nbsp;begin<br> &nbsp; &nbsp;MyProc:=OpenProcess(PROCESS_ALL_ACCESS ,False,hProc);<br> &nbsp; &nbsp;TerminateProcess(MyProc,1);<br> &nbsp; &nbsp;Result:=True;<br> &nbsp;end;<br><br> except<br> &nbsp; &nbsp;//abort all Errors~<br> end;<br> &nbsp; &nbsp; &nbsp; <br>end;<br><br>end.<br>/////////////////////////////////////////<br>library Project1;<br><br>{ Important note about DLL memory management: ShareMem must be the<br> &nbsp;first unit in your library's USES clause AND your project's (select<br> &nbsp;Project-View Source) USES clause if your DLL exports any procedures or<br> &nbsp;functions that pass strings as parameters or function results. This<br> &nbsp;applies to all strings passed to and from your DLL--even those that<br> &nbsp;are nested in records and classes. ShareMem is the interface unit to<br> &nbsp;the BORLNDMM.DLL shared memory manager, which must be deployed along<br> &nbsp;with your DLL. To avoid using BORLNDMM.DLL, pass string information<br> &nbsp;using PChar or ShortString parameters. }<br><br>uses<br> &nbsp;{ExceptionLog,}<br> &nbsp;SysUtils,<br> &nbsp;Classes,<br> &nbsp;Procc in 'Procc.pas';<br><br>{$R *.res}<br>exports IsFoundProc,KillProc;<br><br><br>begin<br>end.
 
提升自身进程权限,然后杀去那个进程,<br>又或者用findwindows得到你的应用程序的句柄,然后sendmessage发送关闭命令...[:)]
 
2楼的兄弟<br>你这个代码是进程隐藏还是杀隐藏进程的?<br><br>另外,后面的<br>/////////////////////////////////////////<br>library Project1;<br><br>{ Important note about DLL memory management: ShareMem must be the<br> &nbsp;first unit in your library's USES clause AND your project's (select<br> &nbsp;Project-View Source) USES clause if your DLL exports any procedures or<br> &nbsp;functions that pass strings as parameters or function results. This<br> &nbsp;applies to all strings passed to and from your DLL--even those that<br> &nbsp;are nested in records and classes. ShareMem is the interface unit to<br> &nbsp;the BORLNDMM.DLL shared memory manager, which must be deployed along<br> &nbsp;with your DLL. To avoid using BORLNDMM.DLL, pass string information<br> &nbsp;using PChar or ShortString parameters. }<br><br>uses<br> &nbsp;{ExceptionLog,}<br> &nbsp;SysUtils,<br> &nbsp;Classes,<br> &nbsp;Procc in 'Procc.pas';<br><br>{$R *.res}<br>exports IsFoundProc,KillProc;<br><br><br>begin<br>end.<br>有啥作用
 
成功了,用findwindows得到应用程序的句柄,然后sendmessage发送关闭命令<br>procedure TForm1.RzBitBtn2Click(Sender: TObject);<br> &nbsp;var <br>h: hwnd;<br>begin<br> &nbsp; &nbsp; &nbsp; h := FindWindow(nil,'Form1');<br> &nbsp; &nbsp; &nbsp; if h &lt;&gt; 0 then SendMessage(h,WM_Close,0,0);<br>end;
 
后退
顶部