Code PB 4.10 | Win XP sp2 (pas testé ailleurs)
Il faut choisir le mode Time dans la procédure suivant ce que l'on veut afficher.
Code : Tout sélectionner
;structure nécessaire à la recherche des processus
Structure PROCESSENTRY33
dwSize.l
cntUsage.l
th32ProcessID.l
th32DefaultHeapID.l
th32ModuleID.l
cntThreads.l
th32ParentProcessID.l
pcPriClassBase.l
dwFlags.l
szExeFile.b[#MAX_PATH]
EndStructure
ProcedureDLL GetPidProcess(Name.s)
Name.s=UCase(Name.s)
Recherche=0
If OpenLibrary(0, "Kernel32.dll")
CreateToolhelpSnapshot = GetFunction(0, "CreateToolhelp32Snapshot")
ProcessFirst = GetFunction(0, "Process32First")
ProcessNext = GetFunction(0, "Process32Next")
If CreateToolhelpSnapshot And ProcessFirst And ProcessNext ; Ensure than all the functions are found
Process.PROCESSENTRY33\dwSize = SizeOf(PROCESSENTRY33)
Snapshot = CallFunctionFast(CreateToolhelpSnapshot, #TH32CS_SNAPPROCESS, 0)
If Snapshot
ProcessFound = CallFunctionFast(ProcessFirst, Snapshot, Process)
While ProcessFound
Nom.s=UCase(PeekS(@Process\szExeFile, -1, #PB_Ascii))
Nom=GetFilePart(Nom)
If Nom=Name
Recherche =1
PID=Process\th32ProcessID
EndIf
ProcessFound = CallFunctionFast(ProcessNext, Snapshot, Process)
Wend
EndIf
CloseHandle_(Snapshot)
EndIf
CloseLibrary(0)
EndIf
ProcedureReturn PID
EndProcedure
;Il y a 2 structures (Structure FILETIME et Structure SYSTEM_INFO) nécessaires pour le ProcessTime, mais elles sont déjà déclarées et il n'y a pas à les ajouter.
Procedure GetProcessusTime(PID.l)
creation.FILETIME
exit.FILETIME
kernel.FILETIME
user.FILETIME
sysinfo.SYSTEM_INFO
GetSystemInfo_(@sysinfo)
numprocs = sysinfo\dwNumberOfProcessors
hProcess = OpenProcess_(#PROCESS_QUERY_INFORMATION, #False, PID)
If GetProcessTimes_(hProcess,@creation,@exit,@kernel,@user) <>0
Time = user\dwLowDateTime ;temps passé à exécuter du code d'application
; Time = kernel\dwLowDateTime ;temps passé à exécuter du code système
; Time = exit\dwLowDateTime ;date et heure d'arrêt du processus
; Time = creation\dwLowDateTime ;date et heure de démarrage du processus
ProcedureReturn Time/1000/numprocs ;conversion en secondes et division par le nombre de processeurs.
EndIf
EndProcedure
pid = GetPidProcess("PureBasic.exe")
Debug FormatDate("%hh:%ii:%ss", GetProcessusTime(pid))
