How to check if Outlook works using vbscript

How to check if Outlook is working using vbscript, I need this for my installation procedure to ask the user to close Outlook before installing my application.

Thanks,

+3
source share
3 answers

You can try to get an Outlook application object using a function GetObject. If the function call succeeds, it means that Outlook is currently running:

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
+7
source
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
+4
source

CheckOutlookAndSendEmail

Sub MailViaOutlook()   Dim OutApp   Dim OutMail   Set OutApp = CreateObject ( "Outlook.Application" )   Set 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

Sub

' Outlook

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

end,

Sub

0

Source: https://habr.com/ru/post/1715148/


All Articles