如何使用vbscript检查Outlook是否正在运行,我的安装过程需要这个,以便在安装我的应用程序之前要求用户关闭outlook。
谢谢,
答案 0 :(得分:7)
您可以尝试使用GetObject
函数获取Outlook Application对象。如果函数调用成功,则表示Outlook当前正在运行:
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
答案 1 :(得分:4)
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
答案 2 :(得分:0)
调用CheckOutlookAndSendEmail
Sub MailViaOutlook() Dim OutApp 昏暗的外出邮件 设置OutApp = CreateObject(“Outlook.Application”) 设置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
'以下功能适用于打开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
结束子 '结束函数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