Code: Select all
Procedure GetPid(FiletoFind$)
kernel32 = OpenLibrary(0, "Kernel32.dll")
OpenLibrary(1, "psapi.dll")
If kernel32
CreateToolhelpSnapshot = GetFunction(0, "CreateToolhelp32Snapshot")
ProcessFirst = GetFunction(0, "Process32First")
ProcessNext = GetFunction(0, "Process32Next")
If CreateToolhelpSnapshot And ProcessFirst And ProcessNext
Process.PROCESSENTRY32\dwSize = SizeOf(PROCESSENTRY32)
Snapshot = CallFunctionFast(CreateToolhelpSnapshot, #TH32CS_SNAPPROCESS, 0)
If Snapshot
ProcessFound = CallFunctionFast(ProcessFirst, Snapshot, Process)
While ProcessFound
PID = Process\th32ProcessID
hProcess = OpenProcess_(#PROCESS_ALL_ACCESS, 0, PID)
If hProcess
Name$ = Space(1024)
CallFunction(1, "GetModuleFileNameExA", hProcess, 0, @Name$, Len(Name$))
CloseHandle_(hProcess)
EndIf
Temp.s = PeekS(@Process\szExeFile)
If Temp <> "[System Process]"
;AddGadgetItem(GD, - 1, Str(PID) + Chr(10) + Temp + Chr(10) + Name$)
If UCase(Temp)=UCase(FiletoFind$)
Debug Temp
PIDFound=PID
EndIf
EndIf
ProcessFound = CallFunctionFast(ProcessNext, Snapshot, Process)
Wend
EndIf
CloseHandle_(Snapshot)
EndIf
EndIf
ProcedureReturn PIDFound
EndProcedure
Pid = GetPid("notepad.exe")
Debug (Pid)