Delphi判断进程是否存在(使用CreateToolhelp32Snapshot)

 
[html] view plain copy
 
  1. program Project2;  
  2.   
  3. uses  
  4.   windows,TLHelp32;  
  5.   
  6. function FindProcess(AFileName:string):boolean;   
  7. var   
  8.     hSnapshot:THandle;  
  9.     lppe:TProcessEntry32;   
  10.     Found:Boolean;   
  11. begin   
  12.     Result:=False;  
  13.     hSnapshot:=CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);   
  14.     lppe.dwSize:=SizeOf(TProcessEntry32);   
  15.     Found:=Process32First(hSnapshot,lppe);   
  16. while Found do  
  17. begin   
  18.     if(lppe.szExeFile = AFileName) then Result:=True;   
  19.     Found:=Process32Next(hSnapshot,lppe);   
  20. end;   
  21. end;  
  22.   
  23. begin  
  24.     if FindProcess('QQ.exe') then  
  25.     MessageBox(0, PChar('QQ存在'), PChar('提示'), MB_OK);  
  26. end.  
 
http://blog.csdn.net/cmdasm/article/details/9961575
posted @ 2016-08-19 23:39  findumars  Views(1454)  Comments(0Edit  收藏  举报