Prozesse auflisten in einer .txt

Eher nicht optimal, aber dennoch ne lösung :D

C++:
#include <windows.h>
#include <tlhelp32.h>
#include <iostream>
#include <fstream>
#include <string>
#include <sstream>

using namespace std;

typedef BOOL (WINAPI *TH32_PROCESS)
             (HANDLE hSnapShot, LPPROCESSENTRY32 lppe);

static TH32_PROCESS pProcess32First = NULL;
static TH32_PROCESS pProcess32Next = NULL;

int main()
{
   PROCESSENTRY32 pe32 = { 0 };
   HANDLE hSnapshot    = NULL;

   HINSTANCE hDll = LoadLibrary("kernel32.dll");


   pProcess32First=(TH32_PROCESS)GetProcAddress(hDll,"Process32First");
   pProcess32Next=(TH32_PROCESS)GetProcAddress(hDll,"Process32Next");

   hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);
   if (hSnapshot != (HANDLE) -1)
   {
pe32.dwSize = sizeof (PROCESSENTRY32);
int proc_cnt=0,thrd_cnt=0;

if (pProcess32First (hSnapshot, &pe32))
{
    ofstream outfile("C:\\prozesse.txt");
    ostringstream outf;
    string outfi;
    do
    {
        outf << pe32.szExeFile;
        outf << "\n";

    } while(pProcess32Next (hSnapshot, &pe32));

    outfi = outf.str();
    cout << outfi << endl;
    outfile << outfi;
    outfile.close();

}

CloseHandle (hSnapshot);
   }

   cin.get();
   return 0;
}

Wenn du es umbedingt mit WritePrivateProfileString machen möchtest dann schau dir mal das hier an: http://www.c-plusplus.de/forum/viewtopic-var-t-is-160682.html ;)
 
Zurück