Überprüfen ob externes Programm aktiv ist

Vektor

Erfahrenes Mitglied
Hallo,

in meinem Programm kann man einen Pfad einer *.exe eingeben, welche dann bei bestimmten Bedingungen gestartet wird.

Jetzt möchte ich aber Verhindern dass mein Programm eine Aktion ausführt, wenn dieses Programm, wessen Pfad natürlich vorher bekannt ist, aktiv ist.

Wie kann ich, egal bei welchem Programm, herausfinden ob das Programm läuft?

Hoffe ihr könnt mir helfen.

Danke
 
Hy, der letzte link ist genau das was ich brauche, ABER ich bekomme eine fehlermeldung!
Der sagt mir:

Zeigt auf »IsEXERunning«
Fehler beim Kompilieren.
Sub oder Funktion nicht definiert!

ich habe den Code aber so übernommen:
API in Module1
Visual Basic:
' zunächst die benötigten API-Deklarationen
Private Declare Function CreateToolhelpSnapshot Lib _
  "Kernel32" Alias "CreateToolhelp32Snapshot" ( _
  ByVal lFlgas As Long, ByVal lProcessID As Long) _
  As Long
 
Private Declare Function ProcessFirst Lib "Kernel32" _
  Alias "Process32First" (ByVal hSnapshot As Long, _
  uProcess As PROCESSENTRY32) As Long
 
Private Declare Function ProcessNext Lib "Kernel32" _
  Alias "Process32Next" (ByVal hSnapshot As Long, _
  uProcess As PROCESSENTRY32) As Long
 
Private Declare Sub CloseHandle Lib "Kernel32" ( _
  ByVal hPass As Long)

Private Const TH32CS_SNAPPROCESS As Long = 2&
Private Const MAX_PATH As Long = 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

' Prüft, ob eine EXE-Datei bereits ausgeführt wird
Private 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
Und meine Abfrage ist:
Visual Basic:
Private Sub Wizard1_FinishClicked()
If IsEXERunning("explorer.exe") Then
   MsgBox "Jepp - Explorer ist gestartet."
Else
   MsgBox "No - Explorer ist gestartet."
End If
End Sub

THX 4 Help
 
Zuletzt bearbeitet:
Hi.

Visual Basic:
Private Function IsEXERunning
Private bedeutet das die Funktion nur im aktuellen Modul sichtbar/verwendbar ist. Kann es sein, das du die Wizard1_FinishClicked Prozedur in einem anderem Modul deklariert hast?

Gruß
 

Neue Beiträge

Zurück