vbscript outlook.application

Cómo comprobar si Outlook se está ejecutando, utilizando vbscript



outlook.application (3)

Cómo comprobar si Outlook se está ejecutando, utilizando vbscript, necesito esto para mi procedimiento de instalación para pedirle al usuario que cierre Outlook antes de instalar mi aplicación.

Gracias,


llamar a CheckOutlookAndSendEmail

Sub MailViaOutlook () Dim OutApp Dim OutMail Establecer OutApp = CreateObject ("Outlook.Application") Establecer OutMail = OutApp.CreateItem (0)

On Error Resume Next With OutMail .to = "youremailid" .CC = "" .BCC = "" .Subject = "your Subject" .Body =" Thanks - .......:)" .Send End With On Error GoTo 0 Set OutMail = Nothing Set OutApp = Nothing

End Sub

La función ''Abajo'' es para Outlook abierto

sub OpenOutlook ()

Dim WshShell Set WshShell=WScript.CreateObject("WScript.Shell") WshShell.run "Outlook" If Err <> 0 then Err.Clear Set ObjOL= CreateObject("Outlook.Application") End If

End sub ''End Function OpenOutlook

Sub CheckOutlookAndSendEmail ()

dim Process, strObject, strProcess Const strComputer = "." strProcess = "OUTLOOK.exe" strObject = "winmgmts://" & strComputer For Each Process in GetObject( strObject ).InstancesOf( "win32_process" ) If UCase( Process.name ) = UCase( strProcess ) Then call MailViaOutlook '' no need to open outlook as it is already open, Hence using the exesting and send email exit sub end if Next call OpenOutlook '' Open Outlook call MailViaOutlook '' send email using outlook

terminara si

End Sub


Puede tratar de obtener el objeto Aplicación de Outlook utilizando la función GetObject . Si la llamada a función tiene éxito, significa que Outlook se está ejecutando actualmente:

On Error Resume Next Dim Outlook: Set Outlook = GetObject(, "Outlook.Application") If Err.Number = 0 Then '' Outlook is running Else '' Outlook is not running Err.Clear End If On Error Goto 0


Dim Process, strObject, strProcess Const strComputer = "." strProcess = "OUTLOOK.exe" IsProcessRunning = False strObject = "winmgmts://" & strComputer For Each Process in GetObject( strObject ).InstancesOf( "win32_process" ) If UCase( Process.name ) = UCase( strProcess ) Then MsgBox "Outlook is running" End If Next