Warum funktioniert die Abfrage mit Process32First und Process32Next nicht?



  • #include <vcl.h>
    #pragma hdrstop
    #include <windows.h>
    #include <tlhelp32.h>
    #include "Unit1.h"
    //---------------------------------------------------------------------------
    #pragma package(smart_init)
    #pragma resource "*.dfm"
    TForm1 *Form1;

    HANDLE snapshot;
    PROCESSENTRY32 pe;
    //---------------------------------------------------------------------------
    __fastcall TForm1::TForm1(TComponent* Owner)
    : TForm(Owner)
    {
    }
    //---------------------------------------------------------------------------
    void __fastcall TForm1::Button1Click(TObject *Sender)
    {
    snapshot=CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,NULL);
    pe.dwSize=sizeof(pe); //prozessor gr??e 32 oder 64bit
    if(Process32First(snapshot, &pe))
    {
    do
    {
    CheckListBox1->Items->Add(ExtractFileName(pe.szExeFile));
    if((ExtractFileName(pe.szExeFile))=="xyz.exe") exit(0);
    }while(Process32Next(snapshot,&pe));
    }
    CloseHandle(snapshot);
    }

    Warum kann ich so den Filename nicht auslesen,obwohl er in der Listbox existiert?



  • Was macht denn ExtractFileName()?
    Für die If Anweisung würde doch pe.szExeFile=="xyz.exe" reichen.



  • Irgendwie verstehe ich nicht so ganz, was genau jetzt das Problem ist - außerdem kannst du Char-Arrays nicht direkt mit == vergleichen, sondern mit lstrcmp o.ä. 🙂


Anmelden zum Antworten