0

目前正在开发一个 VBScript 来自动化我所做的一些肮脏的 PST 摄取工作,并且在从 Outlook 2003 升级到 2007 后我发现了一些问题。

(必须升级以解决 OL2003 中的 RTF 正文问题 ..)

即使在您指示 Outlook 关闭 PST 存储、注销然后销毁对象(设置 objNS = Nothing 等)之后,Outlook 仍会挂起 1-30 秒,具体取决于我正在使用的 PST 文件的大小。 .

我可以轻松解决并延迟(Wscript.Sleep(300)),但我觉得这很脏并且不完全信任它......关于如何让Outlook正确关闭的任何想法?

我也尝试通过 GetObject() 轮询实例,但即使 OUTLOOK.EXE 在任务管理器中仍然可见,它似乎也会返回 False。

我在下面使用的代码:

Function TestPSTInOutlook(strFileName)
' Open PST in Outlook then closes it, primarily to determine
' if Outlook has any difficulty in processing the PST in the
' first place.  Not interested in corruptions per message, just
' PST-wide (and passwords).

    Const olMailItem = 0
    Const olMSG = 3
    Const olDiscard = 1

    On Error Resume Next
    Dim objOL       ' Outlook.Application   
    Dim objNS       ' Outlook.Namespace
    Dim objFolder   ' Outlook.MAPIFolder
    Dim objIS       ' Outlook.Inspector 
    Dim objMail     ' Outlook.MailItem

    Set objOL = CreateObject("Outlook.Application")
    Set objNS = objOL.GetNamespace("MAPI")

    objNS.Logon
    objNS.AddStore strFileName

    If Err.Number <> 0 Then
        loggit_silent = True
        loggit("TestPSTInOutlook(): failed to open " & strFileName & " for reason: " & Err.Description)
        loggit_silent = False
        TestPSTInOutlook = False
    Else
        Set objFolder = objNS.Folders.GetLast
        objFolder.Name = strFileName

        Set objMail = objOL.CreateItem(olMailItem) 
        Set objIS = objMail.GetInspector 

        objIS.Close (olDiscard) 
        objMail.Close (olDiscard)

        objNS.RemoveStore objFolder
        loggit_silent = True
        loggit("TestPSTInOutlook(): success opening " & strFileName)
        loggit_silent = False
        TestPSTInOutlook = True
    End If

' BUG: Outlook 2007 refuses to shut down when told and takes its time - we have to wait otherwise we error  on trying to move the next PST file ...
' Does not exist in OL2003 but if we roll back then we don't get fixed Unicode PST support and degraded  ingestion performance
' 

    objNS.Logoff 
    objOL.Session.Logoff 
    objOL.Quit 

    Set objIS = Nothing 
    Set objMail = Nothing 
    Set objNS = Nothing 
    Set objOL = Nothing 

    Wscript.sleep(300)
End Function

注意:loggit() 纯粹是一个日志功能(发送到标准输出和 debuglog.txt)

4

1 回答 1

0

像这样的函数如何查看outlook.exe是否仍在运行

Function IsRunning(procName)
    strComputer = "."
    Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
    Set colProcesses = objWMIService.ExecQuery("Select * from Win32_Process Where Name = '" & procName & "'")
    If colProcesses.Count > 0 Then
        request = True
    Else
        request = False
    End If
    Set colProcesses = Nothing
    Set objWMIService = Nothing
    IsRunning = request
End Function

然后你可以运行一个循环,直到函数返回 false 像这样

Do While IsRunning("notepad.exe")
Loop
于 2009-11-04T21:34:28.690 回答