Funktion: Dieser Code "killt" eine beliebige Anwendung anhand ihres EXE-Names ...
OpenLibrary musste ich benutzen, da ich immer ein Fehler erhalten habe als ich "CreateToolhelp32Snapshot" Aufrufen wollte --> siehe DEFINITIV: Bug aus diesem Forum
Code: Alles auswählen
#KERNEL32LIB = 999
#TH32CS_SNAPPROCESS = $2
#PROCESS_ALL_ACCESS = #STANDARD_RIGHTS_REQUIRED | #SYNCHRONIZE | $FFF
Structure PROCESSENTRY32
dwSize.l
cntUsage.l
th32ProcessID.l
th32DefaultHeapID.l
th32ModuleID.l
cntThreads.l
th32ParentProcessID.l
pcPriClassBase.l
dwFlags.l
szExeFile.b [#MAX_PATH]
EndStructure
Procedure KillTask(ExeFileName.s)
If OpenLibrary (#KERNEL32LIB, "kernel32.dll")
DefType.PROCESSENTRY32 Proc32
Proc32\dwSize = SizeOf (PROCESSENTRY32)
snap = CallFunction (#KERNEL32LIB, "CreateToolhelp32Snapshot", #TH32CS_SNAPPROCESS, 0)
If snap
ContinueLoop.l = CallFunction (#KERNEL32LIB, "Process32First", snap, @Proc32)
While ContinueLoop <> 0
If UCase(ExeFileName.s) = UCase(PeekS(@Proc32\szExeFile))
TerminateProcess_(OpenProcess_(#PROCESS_ALL_ACCESS, #false,PeekL(@Proc32\th32ProcessID)),0)
EndIf
ContinueLoop.l = CallFunction(#KERNEL32LIB,"Process32Next",snap, @Proc32)
Wend
CloseHandle_ (snap)
EndIf
EndIf
EndProcedure
; BEISPIELAUFRUF
KillTask("apiviewer2004.exe")
ps. Danke nochmal für PureBasic ...