How to check if Outlook is running, using vbscript, I need this for my installation procedure to ask the user to close outlook before installing my application.
Thanks,
How to check if Outlook is running, using vbscript, I need this for my installation procedure to ask the user to close outlook before installing my application.
Thanks,
You could try obtaining the Outlook Application object using the GetObject
function. If the function call succeeds, this 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
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
call 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
End Sub
'Below function is for open 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 if
End Sub