为什么有时有结果有时没有结果?
界面上只有一个ListBox和一个Button。use TLHelp32procedure TForm1.Button1Click(Sender: TObject);
var
  lppe: TProcessEntry32;
  found : boolean;
  Hand : THandle;
begin
  Hand := CreateToolhelp32Snapshot(TH32CS_SNAPALL,0);
  found := Process32First(Hand,lppe);
  while found do
  begin
    ListBox1.Items.Add(StrPas(lppe.szExeFile));//列出所有进程。
    found := Process32Next(Hand,lppe);
  end;
end;

解决方案 »

  1.   


    Hand := CreateToolhelp32Snapshot(TH32CS_SNAPALL,0);lppe.dwSize := SizeOf(FProcessEntry32);  found := Process32First(Hand,lppe);
      

  2.   

    完美解决!
    5星上将,果然不一样!
    不过为什么要加lppe.dwSize := SizeOf(TProcessEntry32);这一句呢?
      

  3.   

    我晕,Sorry,昨天没发现这现有下面这段说明。
    The calling application must set the dwSize member of PROCESSENTRY32 to the size, in bytes, of the structure. Process32First changes dwSize to the number of bytes written to the structure. This will never be greater than the initial value of 
    dwSize, but it may be smaller. If the value is smaller, do not rely on the values of any members whose offsets are greater than this value. 
      

  4.   

    试了一下没有问题啊,每次都可以
    StrPas(lppe.szExeFile)是不是改为string(lppe.szExeFile)