3

如何使用 vbscript 检查 Outlook 是否正在运行,我的安装过程需要这个来要求用户在安装我的应用程序之前关闭 Outlook。

谢谢,

4

3 回答 3

8

您可以尝试使用该GetObject函数获取 Outlook 应用程序对象。如果函数调用成功,这意味着 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
于 2009-08-14T07:34:31.913 回答
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
于 2009-08-14T07:13:25.700 回答
0

调用 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

结束子

'以下功能用于打开 Outlook

子 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 '结束函数 OpenOutlook

子 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

万一

结束子

于 2017-11-09T14:54:44.687 回答