2009-11-04 72 views
0

目前工作的一個VBScript來自動完成一些骯髒的PST攝入的工作,我做的關閉,我也發現了一些問題從Outlook 2003升級到2007年Outlook 2007中似乎從來沒有當指示

(後不得不升級以解決RT200正文問題在OL2003 ..)

即使您指示Outlook關閉PST存儲後,註銷然後銷燬該對象(set 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 

NB:loggit()是純粹的記錄功能(發送到標準輸出和一個debuglog.txt)

回答

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 
+0

奇怪的是,它似乎大部分時間工作,然後我得到一個曾經關閉的問題,它認爲過程已經關閉,但鎖沒有及時清除,無法移動 - 只有大型PST(2- 10 GB) 我不得不做兩件事: *保持檢查員代碼的創建 - 它實際上似乎可以加快關閉Outlook從10秒到約2秒,如果你創建然後銷燬檢查器 *實現一個調用FSO.MoveFile的子程序,如果失敗,等待300ms然後再次嘗試 - 這也有助於系統運行的CPU比預期更高: – knda 2009-11-05 00:28:03

+0

添加正確的答案,因爲它可以在實驗室中正常工作 - 其他人可能會得到不同的里程數,我想,謝謝你ou Tester101 :) – knda 2009-11-05 00:28:40