Das Notes Forum

Lotus Notes / Domino Sonstiges => Tipps und Tricks => Thema gestartet von: eknori am 25.03.02 - 08:10:45

Titel: Laufende Prozesse ermitteln (API)
Beitrag von: eknori am 25.03.02 - 08:10:45
Wie kann man prüfen, ob eine bestimmte Anwendung bereits im Hintergrund läuft?
Mit einer Handvoll API und ein bisschen Lotus Script ist das möglich.
Der Vorteil dieser Function besteht im Unterschied zu vielerorts veröffentlichen
Funktionen zum Thema darin, daß hier der Prozess selbst ( winword.exe, excel.exe etc )
geprüft wird und nicht ein bestimmtes Fesnster Handle mit einer bekannten Überschrift
(Microsoft Winword - Dokument 1)

Der Nachteil ist, das die Funktion nur unter Windows 2000 läuft( evtl auch unter Win 9x ),
da die Function "CreateToolhelpSnapshot" nicht in NT4 enthalten ist.
Soweit zur Kompatibilität der Windows Versionen untereinander !!

Möglicherweise hat jemand eine unter Lotus Scrip lauffähige Funktion für WinNt4.
Ich weiß zwar, welche API Calls ich brauche, kann das aber nicht testen, da ich hier keinen
NT Rechner habe.

'// Diese Zeilen in die DECLARATION section kopieren
Const TH32CS_SNAPPROCESS  = 2&
Const MAX_PATH  = 260

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.dll" Alias "CreateToolhelp32Snapshot"

(Byval lFlags As Long, Byval lProcessID As Long) As Long
Declare Function ProcessFirst Lib "Kernel32.dll" Alias "Process32First" (Byval hSnapShot As Long,

uProcess As PROCESSENTRY32) As Long
Declare Function ProcessNext Lib "Kernel32.dll" Alias "Process32Next" (Byval hSnapShot As Long,

uProcess As PROCESSENTRY32) As Long
Declare Sub CloseHandle Lib "Kernel32.dll" (Byval hPass As Long)
Declare Function FindWindow Lib "user32" Alias"FindWindowA" (Byval lpClassName As String, Byval

lpWindowName As String) As Long
Declare Function PostMessage Lib "user32" Alias "PostMessageA" (Byval hwnd As Long, Byval wMsg As

Long, Byval wParam As Long, lParam As Any) As Long

Const WM_CLOSE = &H10
'// END DECLARATION

Function IsProcessRunningW2K (Filename As String) As Variant
       ' 24.03.2002, Ulrich Krause
     Dim hSnapShot As Long, uProcess As PROCESSENTRY32, RetVal As Long
     
     hSnapShot = CreateToolhelpSnapshot(2&, 0&)
     If hSnapShot = 0 Then Exit Function
     
     uProcess.dwSize = Len(uProcess)
     RetVal = ProcessFirst(hSnapShot, uProcess)
     
     Do While RetVal <> 0
           If Instr(1,Ucase(uProcess.szExeFile), Ucase(Filename), 0 ) > 0 Then
                 IsProcessRunningW2K = True   'YES
                 Exit Function
           End If
           RetVal = ProcessNext(hSnapShot, uProcess)
     Loop
     IsProcessRunningW2K = False ' Process is not running
     Call CloseHandle(hSnapShot)
     
End Function


Sample:

Sub Click(Source As Button)
     Msgbox IsProcessRunningW2K ( "winword.exe" )      
End Sub
Titel: Re: Laufende Prozesse ermitteln (API)
Beitrag von: matze140984 am 21.11.07 - 13:18:51
Hallo in die Runde!

Wenn ich jetzt den Prozess habe!

Wie kann ich ihn in den Vordergrund stellen?

Vielen Dank für eure Mithilfe!!
Titel: Re: Laufende Prozesse ermitteln (API)
Beitrag von: eknori am 21.11.07 - 13:21:14
Das fensterhandle zur ProzessID ermitten und dann BringToTop ( oder so ähnlich )