determining when a process is finished in Win98
Place the following code in a VB module
==========================================================
Public Declare Function CreateToolhelpSnapshot Lib "Kernel32" _
Alias "CreateToolhelp32Snapshot" _
(ByVal lFlags As Long, ByVal lProcessID As Long) As Long
Public Declare Function ProcessFirst Lib "Kernel32" _
Alias "Process32First" _
(ByVal hSnapShot As Long, uProcess As PROCESSENTRY32) As Long
Public Declare Function ProcessNext Lib "Kernel32" _
Alias "Process32Next" _
(ByVal hSnapShot As Long, uProcess As PROCESSENTRY32) As Long
Public Declare Sub CloseHandle Lib "Kernel32" _
(ByVal hPass As Long)
Public Const TH32CS_SNAPPROCESS As Long = 2&
Public Const MAX_PATH As Integer = 260
Public 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
Sub Processes(Procs$(), NumProcesses%)
'Pass the routine an array and an integer variable
'The routine returns the names of all running processes, starting
'at index number 1, up to NumProcesses%
Dim hSnapShot As Long
Dim uProcess As PROCESSENTRY32
Dim r As Long
hSnapShot = CreateToolhelpSnapshot(TH32CS_SNAPPROCESS, 0&)
NumProcesses% = 0
If hSnapShot = 0 Then Exit Sub
uProcess.dwSize = Len(uProcess)
r = ProcessFirst(hSnapShot, uProcess)
Do While r
NumProcesses% = NumProcesses% + 1
a$ = uProcess.szExeFile
pos% = InStr(a$, Chr$(0))
Procs$(NumProcesses%) = Left$(a$, pos% - 1)
If UBound(Procs$) = NumProcesses% Then
ReDim Preserve Procs$(NumProcesses% + 10)
End If
r = ProcessNext(hSnapShot, uProcess)
Loop
Call CloseHandle(hSnapShot)
End Sub
==========================================================
As an example of how to use the above code, place a Timer control on a form, with the following code:
Private Sub Timer1_Timer()
ReDim Procs$(3)
Dim NotepadFlag As Boolean
Call Processes(Procs$(), n%)
Cls
NotepadFlag = False
For i% = 1 To n%
Notepad% = InStr(ucase$(Procs$(i%)), "NOTEPAD")
If Notepad% <> 0 Then
Print "Notepad is running": NotepadFlag = True
Exit For
End If
Next i%
If Not NotepadFlag Then Print "Notepad is not running"
End Sub
Run the program, and open and close the Windows Notepad program.Each time the Timer fires, it will enumerate the processes running under Win98, and notify you as to whether Windows Notepad is running or not.