Thunder93 wrote:Code: Select all
Procedure.b Kernel32_Init()
Shared Kernel32
Protected Retr.b, fExt.s
Kernel32 = OpenLibrary(#PB_Any, "Kernel32.dll")
If Kernel32 <> 0
CompilerIf #PB_Compiler_Unicode : fExt = "W" : CompilerElse : fExt = "A" : CompilerEndIf
Global EnumProcesses.EnumProcesses = GetFunction(Kernel32, "K32EnumProcesses")
Global EnumProcessModules.EnumProcessModules = GetFunction(Kernel32, "K32EnumProcessModules")
Global GetModuleBaseName.GetModuleBaseName = GetFunction(Kernel32, "K32GetModuleBaseName"+fExt)
Retr = 1
EndIf
ProcedureReturn Retr
EndProcedure
Hello Thunder93.
Excellent code. Quite what i was looking for.
Your code, however, fails if the process name contains a space.
For instance, "App123.exe" (
no space) gets found and killed ;
however, "App 123.exe" (
notice the space) gets overlooked; in fact, it never appears on the radar of the GetModuleBaseName() proc.
The problem appears to be in EnumProcessModules(), not in your code. Can you think of a fix ? (apart from renaming the app)
A comment : I see that you keep declaring Global variables
within Procedures.
Why do you that ?
Does it not defeat the very purpose of declaring variables as Global ?
to my way of looking at things, that just adds an unnecessary layer of obscurity to your code.
But you may have a very good reason for organizing your code that way. Please enlighten me.
Related comment : declaring Kernel32 as
Shared without having declared it outside the Procedure previously.
It works, of course, but why do it ? It dulls the sharpness of your code.
But then again, there may be something i'm not seeing here...