d0347朋友的代码有小小的错误,跑不起来,我改了一下,大家可以跑它了:
procedure TForm1.Button1Click(Sender: TObject);
Var
CurrentProcessId, Snapshot: DWord;
MsgProcess: PROCESSENTRY32;
temp:string;
begin
CurrentProcessId := GetCurrentProcess(); // 获得当前(你的)进程的ID
Snapshot:=CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,CurrentProcessId) ;
MsgProcess.dwSize := 296 ;
// 获得第一个进程
Process32First(Snapshot, MsgProcess) ;
// 循环取列举的进程
While (True) Do
Begin
If Process32Next(Snapshot,MsgProcess)= False Then Exit;
temp:=MsgProcess.szExeFile;
If (temp='smss.exe') Then
begin
//If MsgProcess.th32ProcessID= CurrentProcessId Then
ShowMessage(Format('找到已运行程序smss.exe,进程大小=%d字节,进程ID=%d',[MsgProcess.dwSize,MsgProcess.th32ProcessID]));
end ;
End ;
Var
CurrentProcessId, Snapshot: DWord;
MsgProcess: PROCESSENTRY32;
begin
CurrentProcessId := CurrentProcessId(); // 获得当前(你的)进程的ID
Snapshot:=CreateToolhelp32Snapsho(TH32CS_SNAPPROCESS,CurrentProcessId) ;
MsgProcess.dwSize := 296 ;
// 获得第一个进程
Process32First(Snapshot, MsgProcess) ;
// 循环取列举的进程
While (True) Do
Begin
If Process32Next(Snapshot,MsgProcess)= False Then Exit;
If (MsgProcess.szExeFile='QQ.exe') Then
begin
If MsgProcess.th32ProcessID= CurrentProcessId Then
ShowMessage('该程序是QQ');
end ;
End ;