Dies habe ich bisher! Hier wird aber nur eine MSGBOX ausgegeben, wenn z.B. EXCEL noch geöffnet ist. Ich möchte es aber schließen!
(Declarations)
Const MAX_PATH = 260
Private 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
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 Sub CloseHandle Lib "Kernel32" ( Byval hPass As Long)
Const TH32CS_SNAPPROCESS = 2&
------------------------------------------------------------------------------------------------------------------------------------------------------------------------
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
%REM
Beispiel in den ausführenden Script eintragen:
If IsEXERunning("EXCEL.exe") Then
Msgbox "Bitte schliessen Sie die Excel Anwendungen!."
End If
%END REM