.vbs to tell time with Sapi but not interrupt given some open processes
The only issue I see with your answer code is that it will fail to say the time if any executable is running that starts with "zoom" or "teams", such as ZoomIt.exe or TeamSpirit.exe. Otherwise, it can all be done with far fewer lines of code. Here's my version:
Set oSapi = CreateObject("sapi.spvoice")
Set oWMI = GetObject("winmgmts://./root/cimv2")
Function ProcessExist(Exe)
On Error Resume Next
Set oProcesses = oWMI.ExecQuery("Select Name from Win32_Process Where Name = '" & Exe & "'")
If oProcesses.Count>0 Then ProcessExist = True Else ProcessExist = False
On Error Goto 0
End Function
If Not ProcessExist("Zoom.exe") And Not ProcessExist("Teams.exe") Then
Speech = "Il est " & hour(time) & " heures "
If minute(time)>0 Then Speech = Speech & minute(time) & " minutes"
oSapi.Speak Speech
End If
Alternate version that checks a list of Exes:
Const ExeList = "Zoom,Teams"
Set oSapi = CreateObject("sapi.spvoice")
Set oWMI = GetObject("winmgmts://./root/cimv2")
Function ProcessExist(Exe)
On Error Resume Next
Set oProcesses = oWMI.ExecQuery("Select Name from Win32_Process Where Name = '" & Exe & "'")
If oProcesses.Count>0 Then ProcessExist = True Else ProcessExist = False
On Error Goto 0
End Function
Function InProcessList()
ArrExe = Split(ExeList,",")
InProcessList = False
For Each Exe In ArrExe
If ProcessExist(Exe & ".exe") Then InProcessList = True
Next
End Function
If Not InProcessList Then
Speech = "Il est " & hour(time) & " heures "
If minute(time)>0 Then Speech = Speech & minute(time) & " minutes"
oSapi.Speak Speech
End If