CountExeRunning()
Verfasst: 02.01.2019 16:28
Der Code ist dafür da, um rauszufinden, ob das Programm schon mal läuft. Ist recht simpel gehalten, es wird nur nach den EXE-Namen gesucht, ob er vorhanden ist.
ACHTUNG, auf die eigene EXE gibt das Ding natürlich die Zahl 1 aus - die eigene Instanz zählt er mit! Man muss also auf CountExeRunning()>1 testen - dann läuft die exe bereits.
ACHTUNG, auf die eigene EXE gibt das Ding natürlich die Zahl 1 aus - die eigene Instanz zählt er mit! Man muss also auf CountExeRunning()>1 testen - dann läuft die exe bereits.
Code: Alles auswählen
Procedure CountExeRunning(ProcessName.s="")
Protected hSnapShot,iResult,pInfo.PROCESSENTRY32,bProcAvailable
If ProcessName=""
ProcessName=GetFilePart(ProgramFilename())
EndIf
hSnapShot = CreateToolhelp32Snapshot_(#TH32CS_SNAPPROCESS,#Null)
If hSnapShot
pInfo\dwsize = SizeOf(PROCESSENTRY32)
bProcAvailable = Process32First_(hSnapShot, @pInfo)
If bProcAvailable
Repeat
If PeekS(@pInfo\szExeFile,260)= ProcessName
Debug PeekS(@pInfo\szExeFile,260)+" = "+ ProcessName
iresult+1
EndIf
bProcAvailable = Process32Next_(hSnapShot, @pInfo)
Until Not bProcAvailable
EndIf
CloseHandle_(hSnapShot)
ProcedureReturn iResult
EndIf
EndProcedure