Hallo,
@ Rainer: Wie würdest du es in VB6 machen? Vielleicht kann ich
es ja auf .Net übertragen.
Das geht sicher auch noch kürzer, ich hatte aber gerade keine bessere Idee.
Option Explicit
Const TH32CS\_SNAPHEAPLIST = &H1
Const TH32CS\_SNAPPROCESS = &H2
Const TH32CS\_SNAPTHREAD = &H4
Const TH32CS\_SNAPMODULE = &H8
Const TH32CS\_SNAPALL = (TH32CS\_SNAPHEAPLIST Or TH32CS\_SNAPPROCESS Or TH32CS\_SNAPTHREAD Or TH32CS\_SNAPMODULE)
Const TH32CS\_INHERIT = &H80000000
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
Private Declare Function CreateToolhelp32Snapshot Lib "kernel32" (ByVal lFlags As Long, ByVal lProcessID As Long) As Long
Private Declare Function Process32First Lib "kernel32" (ByVal hSnapShot As Long, uProcess As PROCESSENTRY32) As Long
Private Declare Function Process32Next Lib "kernel32" (ByVal hSnapShot As Long, uProcess As PROCESSENTRY32) As Long
Private Declare Sub CloseHandle Lib "kernel32" (ByVal hPass As Long)
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Private Function FindProcess(ByVal PID As Long) As Boolean
Dim hSnapShot As Long, uProcess As PROCESSENTRY32, r As Long
hSnapShot = CreateToolhelp32Snapshot(TH32CS\_SNAPALL, 0&:wink:
uProcess.dwSize = Len(uProcess)
r = Process32First(hSnapShot, uProcess)
Do While r
If uProcess.th32ProcessID = PID Then
FindProcess = True
End If
r = Process32Next(hSnapShot, uProcess)
Loop
CloseHandle hSnapShot
End Function
Private Sub Command1\_Click()
Dim PID As Long
PID = Shell("wscript.exe C:\Test.vbs", 1)
While FindProcess(PID) = True
Sleep 50
Wend
'Hier käme der nächste Aufruf
End
End Sub
Gruß, Rainer