Windows Prozesse ablesen
Übersicht

![]() |
FOODyBetreff: Windows Prozesse ablesen |
![]() Antworten mit Zitat ![]() |
---|---|---|
Hallo liebe User.
Ich würde gerne wissen ob es mit BlitzMax möglich ist Prozesse abzulesen die gerade auf Windows laufen. Halt sowas wie der Taskmanager. Wenn ja wie? Jeder Denkanstoß ist herzlich willkommen ![]() .:: FOODy |
||
![]() |
Markus2 |
![]() Antworten mit Zitat ![]() |
---|---|---|
Dafür gibt es API Funktionen die du in BMax einbinden kannst .
API Guide http://www.allapi.net da sind viele Beispiele in VB6 und auch in Dot Net bei |
||
![]() |
FOODy |
![]() Antworten mit Zitat ![]() |
---|---|---|
Danke für die super Seite, Markus2! ![]() Hoffentlich bin ich blöd genug es hinzukriegen >_> EDIT: Ich bekomm es einfach nicht hin >_> Bin nur bis hierhin gekommen. -_- Was ist hier dran falsch? Code: [AUSKLAPPEN] Framework BRL.Basic
Import BRL.StandardIO Extern "Win32" Function EnumProcesses:Long(lpidProcess:Long,cb:Long,cbNeeded:Long) EndExtern Das ist glaub ich in VB: (Quelle: API-Guide) Zitat: Declare Function EnumProcesses Lib "PSAPI.DLL" (ByRef lpidProcess As Long, ByVal cb As Long, ByRef cbNeeded As Long) As Long
Parameter Beschreibung: (Quelle: API-Guide) Zitat: · lpidProcess
[out] Pointer to an array that receives the list of process identifiers. · cb [in] Specifies the size, in bytes, of the lpidProcess array. · cbNeeded [out] Receives the number of bytes returned in the lpidProcess array. Return: (Quelle: API-Guide) Zitat: If the function succeeds, the return value is nonzero.
If the function fails, the return value is zero. To get extended error information, call GetLastError. Ich verzweifel noch mit diesem Proggy ;_; |
||
![]() |
Markus2 |
![]() Antworten mit Zitat ![]() |
---|---|---|
ByRef heißt bei Referenz und die Funk. schreibt dir da nen Wert zurück
in BMax müßtest du var hinter den Parameter setzen . Ich glaube so Function EnumProcesses:int(lpidProcess:intvar,cb:int,cbNeeded:int var) und Long in BMax ist 64 Bit und in VB6 nur 32 Bit also 4 Byte |
||
![]() |
FOODy |
![]() Antworten mit Zitat ![]() |
---|---|---|
Ja das mit dem Var hatte ich schon davor getestet. (hab rumprobiert und so)
Was neu für mich ist ist nur das Int statt Long ^^ Das problem ist das es nicht geht oder ich etwas falsch mache >_> Hier ist der Test code: Zitat: Framework BRL.Basic
Import BRL.StandardIO 'psapi Extern "Win32" Function EnumProcesses:Int(lpidProcess:Int Var,cb:Int,cbNeeded:Int Var) EndExtern Local d:Int Local a:Int Print EnumProcesses(d,4,a) BlitzMax spuckt dies hier aus: Zitat: Building main
Compiling:main.bmx flat assembler version 1.64 3 passes, 602 bytes. Linking:main.exe C:/Dokumente und Einstellungen/FOODy/Desktop/BlitzMax Projekte/Zeugs/Process/.bmx/main.bmx.console.release.win32.o(code+0x58): undefined reference to `EnumProcesses@12' Build Error: Failed to link C:/Dokumente und Einstellungen/FOODy/Desktop/BlitzMax Projekte/Zeugs/Process/main.exe Process complete . . . |
||
![]() |
Markus2 |
![]() Antworten mit Zitat ![]() |
---|---|---|
Ich grüble gerade woher BMax wissen soll das es in PSAPI.DLL steckt !?
Über den Dateinamen der bmx Datei ? Ich habe selber noch nie in BMax APIs eingebunden . Haste da mal rein geguckt ? \BlitzMax\mod\pub.mod\win32.mod |
||
![]() |
BtbN |
![]() Antworten mit Zitat ![]() |
---|---|---|
Da fehlt der Import der Lib!
Code: [AUSKLAPPEN] ?win32
Import "-lpsapi" Extern "Win32" Function EnumProcesses:Int(lpidProcess:Int Var,cb:Int,cbNeeded:Int Var) EndExtern ? Linker Error heißt immer, das der Code zwar erfolgreich kompiliert wurde, ihm aber irgend was zum zusammenbauen der Exe fehlt. Hier in diesem Fall die libpsapi. |
||
![]() |
FOODy |
![]() Antworten mit Zitat ![]() |
---|---|---|
Da hab ich als erstes geschaut.
(Also in allen bmx-Files im win32.mod Ordner) Hmmm... ich habs jetzt mal so versucht: Zitat: Framework BRL.Basic
Import BRL.StandardIO Import PUB.Win32 Local ApiFile:String = String(getenv_("windir"))+"\system32\psapi.dll" Global ApiHandle:Int = LoadLibraryA(ApiFile) If(ApiHandle = 0) Throw("Fehler") Global EnumProcesses:Int(lpidProcess:Int Var,cb:Int,cbNeeded:Int Var) = GetProcAddress(ApiHandle,"EnumProcesses") Local d:Int Local a:Int Print EnumProcesses(d,4,a) Bei mir gibt er 1 zurück. Aber was hat die für ne bedeutung? >_> EDIT: @BORNtobeNAMELESS: Klingt logisch. Aber irgendwie gehts bei mir immernoch nicht... Zitat: Building main
Compiling:main.bmx flat assembler version 1.64 3 passes, 588 bytes. Linking:main.exe C:/Programmierung/BlitzMax/bin/ld.exe: cannot find -lpsapi Build Error: Failed to link C:/Dokumente und Einstellungen/FOODy/Desktop/BlitzMax Projekte/main.exe Process complete |
||
- Zuletzt bearbeitet von FOODy am Di, Jul 04, 2006 18:50, insgesamt 2-mal bearbeitet
![]() |
BtbN |
![]() Antworten mit Zitat ![]() |
---|---|---|
Da laut MSDN der rückgabe-Type von der Funktion 'bool' ist, heißt das: Erfolgreich abgeschlossen | ||
![]() |
FOODy |
![]() Antworten mit Zitat ![]() |
---|---|---|
ok...
Und was bringt der befehl? xD Ich möcht ja "nur" die gestarteten Windows Prozesse mit BM ablesen. Aber wie soll ich das mit dem Befehl anstellen. >_> Wieso muss das immer so übelst kompliziert sein ._." Da gibts auch noch sowas wie: - Process32first - Process32next - ... Bitte helft den armen FOODy >_> |
||
![]() |
Markus2 |
![]() Antworten mit Zitat ![]() |
---|---|---|
also mit dem Import "-lpsapi" geht tatsächlich ![]() VB6 Code: [AUSKLAPPEN] Option Explicit Private Const TH32CS_SNAPPROCESS As Long = 2& Private Const MAX_PATH As Integer = 260 Private Type PROCESSENTRY32 dwSize As Long cntUsage As Long th32ProcessID As Long th32DefaultHeapID As Long th32ModuleID As Long cntThreads As Long th32ParentProcessID As Long pcPriClassBase As Long dwFlags As Long szExeFile As String * MAX_PATH End Type Private Declare Function CreateToolhelpSnapshot Lib "kernel32" _ Alias "CreateToolhelp32Snapshot" _ (ByVal lFlags As Long, ByVal lProcessID As Long) As Long Private Declare Function ProcessFirst Lib "kernel32" _ Alias "Process32First" _ (ByVal hSnapShot As Long, uProcess As PROCESSENTRY32) As Long Private Declare Function ProcessNext Lib "kernel32" _ Alias "Process32Next" _ (ByVal hSnapShot As Long, uProcess As PROCESSENTRY32) As Long Private Declare Sub CloseHandle Lib "kernel32" _ (ByVal hPass As Long) Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long Private Declare Function GetExitCodeProcess Lib "kernel32" (ByVal hProcess As Long, lpExitCode As Long) As Long Private Declare Function TerminateProcess Lib "kernel32" (ByVal hProcess As Long, ByVal uExitCode As Long) As Long 'Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long Dim Procs() As PROCESSENTRY32 Dim NOP% Private Sub Command1_Click() Auflisten End Sub Private Sub Form_Load() Auflisten End Sub Private Sub List1_Click() Dim i, a&, EC& Dim Task$ Dim ProcessID, hProcess As Long Task = Procs(List1.ListIndex).szExeFile If MsgBox("Wollen Sie folgendes Programm wirklich beenden ?" & vbCrLf & Task, vbYesNo, "Achtung !") = vbNo Then Exit Sub ProcessID = Procs(List1.ListIndex).th32ProcessID hProcess = OpenProcess(&H1, 1, ProcessID) a = GetExitCodeProcess(hProcess, EC) a = TerminateProcess(hProcess, EC) CloseHandle hProcess Auflisten End Sub Private Sub Auflisten() Dim hSnapShot As Long Dim uProcess As PROCESSENTRY32 Dim r As Long ReDim Procs(0) List1.Clear hSnapShot = CreateToolhelpSnapshot(TH32CS_SNAPPROCESS, 0&) If hSnapShot = 0 Then Exit Sub uProcess.dwSize = Len(uProcess) r = ProcessFirst(hSnapShot, uProcess) Dim t As String Do While r t$ = ztrim(uProcess.szExeFile) If is_r_in(t$, "KERNEL32.DLL") Then t$ = "+ " & t$ & " (Windows Haupt DLL)" If is_r_in(t$, "MSGSRV32.EXE") Then t$ = "+ " & t$ & " (Windows ?)" If is_r_in(t$, "MPREXE.EXE") Then t$ = "+ " & t$ & " (Windows ?)" If is_r_in(t$, "MMTASK.TSK") Then t$ = "+ " & t$ & " (Windows ?)" If is_r_in(t$, "EXPLORER.EXE") Then t$ = "+ " & t$ & " (Windows Explorer)" If is_r_in(t$, "SYSTRAY.EXE") Then t$ = "+ " & t$ & " (Windows)" If is_r_in(t$, "DIRECTCD.EXE") Then t$ = "+ " & t$ & " (CD wie Diskette benutzen)" If is_r_in(t$, "STIMON.EXE") Then t$ = "+ " & t$ & " (Flachbett Scanner)" If is_r_in(t$, "WMIEXE.EXE") Then t$ = "+ " & t$ & " (Windows ?)" If is_r_in(t$, "TASKMON.EXE") Then t$ = "+ " & t$ & " (Windows Task Monitor)" If is_r_in(t$, "EM_EXEC.EXE") Then t$ = "+ " & t$ & " (Creative Soundkarte)" If is_r_in(t$, "9X8Start.EXE") Then t$ = "+ " & t$ & " (Creative Soundkarte)" If is_r_in(t$, "VB6.EXE") Then t$ = "+ " & t$ & " (Visual Basic Editor)" List1.AddItem t$ r = ProcessNext(hSnapShot, uProcess) NOP = NOP + 1 ReDim Preserve Procs(NOP) Procs(NOP).szExeFile = uProcess.szExeFile Procs(NOP).cntThreads = uProcess.cntThreads Procs(NOP).th32ProcessID = uProcess.th32ProcessID Procs(NOP).th32ParentProcessID = uProcess.th32ParentProcessID Loop Call CloseHandle(hSnapShot) End Sub Private Function ztrim(ByVal z As String) As String Dim x1 As Long x1 = InStr(z, vbNullChar) If x1 > 1 Then z = Mid$(z, 1, x1 - 1) End If If x1 = 1 Then z = "" End If ztrim = z End Function Private Function is_r_in(ByVal st As String, ByVal such As String) As Boolean is_r_in = False If UCase(Right$(st, Len(such))) = UCase(such) Then is_r_in = True End Function |
||
Übersicht


Powered by phpBB © 2001 - 2006, phpBB Group