Abfrage ob Programm offen

  • Sonstige

Es gibt 1 Antwort in diesem Thema. Der letzte Beitrag () ist von Unknown.

    Abfrage ob Programm offen

    Ich möchte in Word-VB eine Abfrage machen ob Outlook geöffnet ist. Also wenn Outlook nicht offen dann öffnen und weitermachen sonst nur weitermachen. Wie sieht denn dazu der Befehl aus.

    thanx2u
    punker23
    Schreib das mal in ein Modul:

    <pre>
    Private Declare Function CreateToolhelpSnapshot Lib "kernel32" Alias _
    "CreateToolhelp32Snapshot" (ByVal lFlags 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 Integer = 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



    Function IsAppRunning(ExeName As String) As Boolean
    On Error Resume Next

    Dim hSnapShot As Long
    Dim uProcess As PROCESSENTRY32
    Dim RetVal As Long

    IsAppRunning = False

    hSnapShot = CreateToolhelpSnapshot(TH32CS_SNAPPROCESS, 0&)

    uProcess.dwSize = Len(uProcess)
    RetVal = ProcessFirst(hSnapShot, uProcess)

    Do While RetVal <> 0
    uProcess.szExeFile = Left$(uProcess.szExeFile, InStr(uProcess.szExeFile, Chr$(0)) - 1)

    If InStr(1, uProcess.szExeFile, ExeName, vbTextCompare) Then
    IsAppRunning = True
    Exit Do
    End If

    RetVal = ProcessNext(hSnapShot, uProcess)
    Loop

    CloseHandle hSnapShot

    If Err.Number <> 0 Then
    Err.Clear
    End If
    End Function
    </pre>

    Und ruf dann die Funktion mit dem EXE-Namen von Outlook auf.