fb:porticula NoPaste
Tipp zu IsEXERunning
Uploader: | Sebastian |
Datum/Zeit: | 30.01.2008 22:43:41 |
'Is Exe Running:
'Versuch einer Protierung nach FB von VB
'Original Code VB: http://www.vbarchiv.net/archiv/tipp_details.php?pid=572
Const False=0, True=Not False
Const TH32CS_SNAPPROCESS As Long = 2
Const MAX_PATH As Long = 260
Type PROCESSENTRY32
dwSize As Long
cntUsage As Long
th32ProcessID As Long
th32DefaultHeapID As Long
th32ModuleID As Long
cntThreads As Long
th32ParentProcessID As Long
pcPriClassBase As Long
dwflags As Long
szexeFile As String * MAX_PATH
End Type
' zunächst die benötigten API-Deklarationen
Declare Function CreateToolhelpSnapshot Lib _
"Kernel32" Alias "CreateToolhelp32Snapshot" ( _
ByVal lFlgas As Long, ByVal lProcessID As Long) _
As Long
Declare Function ProcessFirst Lib "Kernel32" _
Alias "Process32First" (ByVal hSnapshot As Long, _
uProcess As PROCESSENTRY32) As Long
Declare Function ProcessNext Lib "Kernel32" _
Alias "Process32Next" (ByVal hSnapshot As Long, _
uProcess As PROCESSENTRY32) As Long
Declare Function CloseHandle Lib "kernel32" Alias "CloseHandle" (ByVal hObject As Long) As Long
Declare Function IsEXERunning(ByVal sFilename As String) As Long
Print IsEXERunning("notepad.exe")
Sleep
End
' Prüft, ob eine EXE-Datei bereits ausgeführt wird
Function IsEXERunning(ByVal sFilename As String) As Long
Dim lSnapshot As Long
Dim uProcess As PROCESSENTRY32
Dim nResult As Long
' "Snapshot" des aktuellen Prozess ermitteln
lSnapshot = CreateToolhelpSnapshot(TH32CS_SNAPPROCESS, 0)
If lSnapshot <> 0 Then
uProcess.dwSize = Len(uProcess)
' Ersten Prozess ermitteln
nResult = ProcessFirst(lSnapshot, uProcess)
Do Until nResult = 0
' Prozessliste durchlaufen
If InStr(LCase(uProcess.szexeFile), LCase(sFilename)) > 0 Then
' Jepp - EXE gefunden
IsEXERunning = True
Exit Do
End If
' nächster Prozess
nResult = ProcessNext(lSnapshot, uProcess)
Loop
' Handle schliessen
CloseHandle lSnapshot
End If
End Function