Windows Threads auslesen
Verfasst: 22.11.2015 13:24
Hallo Zusammen,
ich versuche gerade alle Threads des Systems auszulesen ... leider klappt das nicht wie vorgesehen.
GetLastError_() liefert nach Thread32_First_() FehlerCode 18 ... aus MSDN: Code 18 (0x12) = There are no more files.
Hat jemand einen Rat oder eine Idee?
Windows 10 64Bit, PB 5.40 32/64, Unicode Exe. an, Administratormodus an/aus (keinen Unterschied)
PS: ohne Unicode funktioniert auch das erste Beispiel nicht, was aber im Moment keine Rolle spielen sollte
ich versuche gerade alle Threads des Systems auszulesen ... leider klappt das nicht wie vorgesehen.
GetLastError_() liefert nach Thread32_First_() FehlerCode 18 ... aus MSDN: Code 18 (0x12) = There are no more files.
Hat jemand einen Rat oder eine Idee?
Windows 10 64Bit, PB 5.40 32/64, Unicode Exe. an, Administratormodus an/aus (keinen Unterschied)
Code: Alles auswählen
EnableExplicit
Define Snapshot
Define ThE32.THREADENTRY32
Define PE32.PROCESSENTRY32
; Funktioniert
PE32\dwSize = SizeOf(PE32)
Snapshot = CreateToolhelp32Snapshot_(#TH32CS_SNAPPROCESS, 0)
If Snapshot
If Process32First_(Snapshot, @PE32)
Repeat
Debug "==========="
Debug "Name: " + PeekS(@PE32\szExeFile)
Debug "PID: " + Str(PE32\th32ProcessID)
Debug "Parent PID:: " + Str(PE32\th32ParentProcessID)
Debug "ThreadCount: " + Str(PE32\cntThreads)
Debug "----------"
Until Process32Next_(Snapshot, @PE32) = #False
EndIf
CloseHandle_(Snapshot)
EndIf
Debug "/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/"
; funtktioniert NICHT
ThE32\dwSize = SizeOf(ThE32)
Snapshot = CreateToolhelp32Snapshot_(#TH32CS_SNAPTHREAD, 0)
If Snapshot
If Thread32First_(Snapshot, @ThE32)
Repeat
Debug "==========="
Debug "PID: " + Str(ThE32\th32OwnerProcessID)
Debug "TID: " + Str(ThE32\th32ThreadID)
Debug "----------"
Until Thread32Next_(Snapshot, @ThE32)
EndIf
CloseHandle_(Snapshot)
EndIf
; Hier noch ein Ausschnitt von einem Beispielcode aus MSDN
; ========================================================
;
; BOOL ListProcessThreads( DWORD dwOwnerPID )
; {
; HANDLE hThreadSnap = INVALID_HANDLE_VALUE;
; THREADENTRY32 te32;
;
; // Take a snapshot of all running threads
; hThreadSnap = CreateToolhelp32Snapshot( TH32CS_SNAPTHREAD, 0 );
; If( hThreadSnap == INVALID_HANDLE_VALUE )
; Return( FALSE );
;
; // Fill in the size of the Structure before using it.
; te32.dwSize = SizeOf(THREADENTRY32 );
;
; // Retrieve information about the first thread,
; // And exit If unsuccessful
; If( !Thread32First( hThreadSnap, &te32 ) )
; {
; printError( TEXT("Thread32First") ); // Show cause of failure
; CloseHandle( hThreadSnap ); // Must clean up the snapshot object!
; Return( FALSE );
; }
;
; // Now walk the thread List of the system,
; // And display information about each thread
; // associated With the specified process
; do
; {
; If( te32.th32OwnerProcessID == dwOwnerPID )
; {
; _tprintf( TEXT("\n THREAD ID = 0x%08X"), te32.th32ThreadID );
; _tprintf( TEXT("\n base priority = %d"), te32.tpBasePri );
; _tprintf( TEXT("\n delta priority = %d"), te32.tpDeltaPri );
; }
; } While( Thread32Next(hThreadSnap, &te32 ) );
;
; _tprintf( TEXT("\n"));
;
; // Don't forget to clean up the snapshot object.
; CloseHandle( hThreadSnap );
; Return( TRUE );
; }