Option Compare Database
Private Declare PtrSafe Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Dim pHandle As Variant
Public Sub cmdStart_Click()
pHandle = 1
OpenNotepad (pHandle)
End Sub
Sub OpenNotepad(pHandle)
Debug.Print pHandle
pHandle = Shell("C:\Program Files (x86)\BraveSoftware\Brave-Browser\Application\brave.exe", vbNormalFocus)
Debug.Print "Brave handle = " & pHandle
Call WaitSeconds(10)
CloseProgram pHandle
pHandle = Shell("C:\Program Files (x86)\Mozilla Firefox\firefox.exe") ', vbNormalFocus)
Debug.Print "Firefox handle = " & pHandle
Call WaitSeconds(10)
CloseProgram pHandle
pHandle = Shell("D:\Program Files\Vivaldi\Application\vivaldi.exe", vbNormalFocus)
Debug.Print "Vivaldi handle = " & pHandle
Call WaitSeconds(10)
CloseProgram pHandle
pHandle = Shell("D:\Program Files\Opera\launcher.exe", vbNormalFocus)
Debug.Print "Opera handle = " & pHandle
Call WaitSeconds(10)
CloseProgram pHandle
pHandle = Shell("C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe", vbNormalFocus)
Debug.Print "Edge handle = " & pHandle
Call WaitSeconds(10)
CloseProgram pHandle
End Sub
Sub CloseProgram(TargetPHandle As Variant)
Shell "TaskKill /F /PID " & TargetPHandle, vbHide
Debug.Print TargetPHandle & " killed"
End Sub
Public Sub WaitSeconds(Seconds)
On Error GoTo PROC_ERR
Dim datTime As Date
Seconds = Int(Seconds)
datTime = DateAdd("s", Seconds, Now)
Do
Sleep 100 ' Yield to other programs (better than using DoEvents which eats up all the CPU cycles)
DoEvents
Loop Until Now >= datTime
PROC_EXIT:
Exit Sub
PROC_ERR:
MsgBox "Error: " & Err.Number & ". " & Err.Description, , "modDateTime.WaitSeconds"
Resume PROC_EXIT
End Sub