本文整理自网络,侵删。
Function GetProcessHandleAsName(Name:String):THandle;Var Hd,Hs:THandle; dExit:Cardinal; Tmp,Tmp1:String; Lp:TProcessEntry32;begin Result:=0; Lp.dwSize:=sizeof(TProcessEntry32); Hd:=CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0); if Process32First(Hd,Lp) then Repeat Tmp:=UpperCase(Trim(Name)); Tmp1:=Trim(UpperCase(Lp.szExeFile)); if AnsiPos(Tmp,Tmp1)>0 then begin Result:=OpenProcess(PROCESS_ALL_ACCESS,true,Lp.th32ProcessID); break; end Until Process32Next(Hd,Lp)=False;end;
procedure CreateProc;Var siStartupInfo:STARTUPINFO; saProcess,saThread:SECURITY_ATTRIBUTES; piProcInfo:PROCESS_INFORMATION; Hd:Cardinal; ProcessHd:THandle; Hds:THandle; Str:String;begin ProcessHd:=GetProcessHandleAsName('Explorer'); if ProcessHd=0 then Exit; if OpenProcessToken(ProcessHd,TOKEN_ALL_ACCESS,Hds) then if DuplicateTokenEx(Hds,TOKEN_ALL_ACCESS,nil,SecurityIdentification,TokenPrimary,Hd) then begin ZeroMemory(@siStartupInfo,sizeof(siStartupInfo)); siStartupInfo.cb:=sizeof(siStartupInfo); saProcess.nLength:=sizeof(saProcess); saProcess.lpSecurityDescriptor:=nil; saProcess.bInheritHandle:=false; saThread.nLength:=sizeof(saThread); saThread.lpSecurityDescriptor:=nil; saThread.bInheritHandle:=false; CreateProcessAsUser(Hd,nil,PChar(ProcessName),nil,nil,false, CREATE_DEFAULT_ERROR_MODE,nil,nil,siStartupInfo,piProcInfo); end;end;
相关阅读 >>
Delphi xe 自己编辑xe2 vcl style(皮肤/skin)
Delphi idhashmessagedigest, idhash, idglobal md5
Delphi windows 底下根据一个进程的名字杀死一个进程的代码
Delphi xe mysql数据库操作类 mysqlhelper
更多相关阅读请进入《Delphi》频道 >>