刚写了个,呵呵~<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
char):boolean;stdcall;<br>function IsFoundProc(AName
Char):Boolean;stdcall;<br>function FoundProc(AName
Char):THandle;stdcall;<br>function KillProc(AName
Char):Boolean;stdcall;<br><br>implementation<br><br>function AdjustProcessPrivilege(ProcessHandle:THandle;Token_Name
char):boolean;stdcall;<br>var<br>Token:Cardinal;<br>TokenPri:_TOKEN_PRIVILEGES;<br>ProcessDest:int64;<br>l
WORD;<br>begin<br> Result:=False;<br> if OpenProcessToken(ProcessHandle,TOKEN_Adjust_Privileges,Token) then<br> begin<br> if LookupPrivilegeValue(nil,Token_Name,ProcessDest) then<br> begin<br> TokenPri.PrivilegeCount:=1;<br> TokenPri.Privileges[0].Attributes:=SE_PRIVILEGE_ENABLED;<br> TokenPri.Privileges[0].Luid:=ProcessDest;<br> l:=0;<br> //更新进程令牌,成功返回TRUE<br> if AdjustTokenPrivileges(Token,False,TokenPri,sizeof(TokenPri),nil,l) then<br> Result:=True;<br> end;<br> end;<br>end;<br><br>function IsFoundProc(AName
Char):Boolean;stdcall;<br>begin<br> Result:=FoundProc(AName)<>0;<br>end;<br><br><br>function FoundProc(AName
Char):THandle;stdcall;<br>var<br> hSnapShot:THandle;<br> bExist:Boolean;<br> pProcess
PROCESSENTRY32;<br><br> sProcName
Char;<br>begin<br> Result:=0;<br> hSnapShot := CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); //创建进程快照<br> If hSnapShot = 0 Then Exit;<br> GetMem(pProcess,SizeOf(TProcessEntry32));<br> //FillChar(pProcess,SizeOf(TProcessEntry32),0);<br> //ShowMessage(IntToStr(SizeOf(TProcessEntry32)));<br> pProcess^.dwSize := SizeOf(TProcessEntry32);<br> bExist:=Process32First(hSnapShot, pProcess^);<br> if (not bExist) then FreeMem(pProcess);<br> While (bExist) do<br> begin<br> sProcName:=pProcess.szExeFile;<br> if AnsiCompareText(sProcName,AName)=0 then<br> begin<br> Result:=pProcess.th32ProcessID;<br> Exit;<br> end; <br> //FillChar(pProcess,SizeOf(TProcessEntry32),0);<br> pProcess^.dwSize := SizeOf(TProcessEntry32);<br> bExist:=Process32Next(hSnapShot, pProcess^);<br> end;<br> FreeMem(pProcess);<br> CloseHandle(hSnapShot);<br>end;<br><br>function KillProc(AName
Char):Boolean;stdcall;<br>var<br> hProc:THandle;<br> MyProc:HWND;<br>begin<br> Result:=False;<br> try<br> hProc:=FoundProc(AName);<br> if hProc=0 then Exit;<br><br> if AdjustProcessPrivilege(GetCurrentProcess,'SeDebugPrivilege') then<br> begin<br> MyProc:=OpenProcess(PROCESS_ALL_ACCESS ,False,hProc);<br> TerminateProcess(MyProc,1);<br> Result:=True;<br> end;<br><br> except<br> //abort all Errors~<br> end;<br> <br>end;<br><br>end.<br>/////////////////////////////////////////<br>library Project1;<br><br>{ Important note about DLL memory management: ShareMem must be the<br> first unit in your library's USES clause AND your project's (select<br> Project-View Source) USES clause if your DLL exports any procedures or<br> functions that pass strings as parameters or function results. This<br> applies to all strings passed to and from your DLL--even those that<br> are nested in records and classes. ShareMem is the interface unit to<br> the BORLNDMM.DLL shared memory manager, which must be deployed along<br> with your DLL. To avoid using BORLNDMM.DLL, pass string information<br> using PChar or ShortString parameters. }<br><br>uses<br> {ExceptionLog,}<br> SysUtils,<br> Classes,<br> Procc in 'Procc.pas';<br><br>{$R *.res}<br>exports IsFoundProc,KillProc;<br><br><br>begin<br>end.