1 1 1 1 1 1 1 1 1 1 Rating 4.40 (5 Votes)

Problemstellung:

Nur für 32Bit Office Versionen

Wie kann ich mit Access prüfen, ob ein bestimmtes Programm bereits läuft?
Lösung mittels API Funktionen

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

Aufruf:

Dim AppRun As Boolean
 If IsEXERunning("winword.exe") Then AppRun = True 'z.B. WinWord 

Die Variable "AppRun" würde den Wert True annehmen wenn Word bereits läuft.

 

Ähnliche Artikel

You have no rights to post comments

Login Form

Neueste Artikel

SQL zu VBA Konverter
26. Oktober 2018
Problemstellung: Nur für 32Bit Office Versionen Gibt es eine Möglichkeit SQL-Code einer Abfrage so zu konvertieren das der Code in VBA genutzt werden kann? Lösung: Bis Access 2010 gibt das Tool...
1.png5.png8.png6.png1.png7.png8.png
Heute281
Gestern642
Diese Woche2336
Dieser Monat6052
Total1586178

  • IP: 18.224.32.86
  • Browser: Unknown
  • Version:
  • OS: Unknown

Online

3
Online

20. April 2024

Letzte Kommentare

  • Berechnen von Zeiträumen als Abfragekriterium

    elmard 02.02.2021 21:02
    1000 Dank
    für diese Datenbankanwendung! Eine sehr gute Umsetzung mit den vielen Möglichkeiten des Datums.

    Weiterlesen...

     
  • SQL zu VBA Konverter

    Tommy Admin 03.11.2019 16:33
    RE: SQL zu VBA Konverter
    Hallo Elmard, danke für die Info. :lol:

    Weiterlesen...

     
  • SQL zu VBA Konverter

    elmard 03.11.2019 14:49
    Bei SmartTools neue Version 4.0
    Dieses Tool liegt inzwischen in der Version 4 vor und läuft nun auch von A2013 und A2016 sowie im ...

    Weiterlesen...

     
  • Workshop zur Benutzung des Multi-Column TreeView Control unter MS-Access

    TommyK 27.02.2019 06:52
    Workshop
    Hallo mpegjunkie, danke für Dein Feedback. Schön das Dir Workshop weiter hilft. :D

    Weiterlesen...

     
  • Workshop zur Benutzung des Multi-Column TreeView Control unter MS-Access

    mpegjunkie 26.02.2019 20:10
    Perfekter Workshop
    Hallo Tommy, perfekter Workshop, toll und umfassend erläutert. Jetzt nutze ich diese Controls auch.

    Weiterlesen...