TKSoft-Online

Prüfung ob ein Programm bereits läuft PDF Drucken E-Mail
( 4 Votes )
MS-Access Codes - Codeschnipsel MS-Access System und PC-System
  
Donnerstag, den 27. Dezember 2007 um 01:00 Uhr

Problemstellung:

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 LongByVal lProcessID As LongAs 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 StringAs 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.

DatumKlicks
Total4759
Do. 241
Mi. 238
Di. 222
Mo. 214
So. 204
Sa. 191
Fr. 186
Aktualisiert ( Donnerstag, den 01. Juli 2010 um 12:47 Uhr )
 

Kommentare  

 
0 # TommyK 2008-10-28 14:00
User Donti hat heraus gefunden das sich mit der Funktion
alle geöffneten Wordinstanzen schließen lassen.
z.B.:
Code:If IsEXERunning("winword.exe" ) Then <br /> Dim oWord As Word.Application <br /> Set oWord = GetObject(, "Word.Application" ) <br /> With oWord <br /> .Application.Quit <br /> End With <br /> Set oWord = Nothing <br />End If
Antworten | Antworten mit Zitat | Zitieren
 

Kommentar schreiben


Sicherheitscode
Aktualisieren

Login

Latest Comments

Latest Forum Posts

Mehr »

Download Statistik

41 Kategorien
187 Dateien
173466 Downloads