2013-03-24 38 views
3

我在查詢之前搜索並未找到適用於我的代碼的任何內容。另外我所嘗試的是在代碼中評論。錯誤800706BE(遠程過程調用失敗)出現在For..Next循環中,並且每次都以不同的隨機迭代次數中斷循環。 我想念什麼以及如何解決這個(簡單)代碼?WMI Win32_Directory在For循環中失敗,出現錯誤800706BE遠程過程調用失敗

'List All the Folders on a Computer 
strComputer = "." 
Set objWMIService = GetObject("winmgmts:" _ 
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") 
'With objWMIService.Security_ 
' .impersonationlevel = 3 
' For I = 1 To 27 
'  .Privileges.Add(I) 
' Next 
'End With '--------------------------not help at all! 
Set colFolders = objWMIService.ExecQuery("Select * from Win32_Directory") 
cnt = 0 
'Do Until IsObject(colFolders) '-----not help at all! 
' WScript.Sleep 500 
'Loop 
On Error Resume Next 'enabled to get extra info from SWbemLastError 
For Each objFolder In colFolders 
    Wscript.Echo objFolder.Name 
    cnt = cnt + 1 
' WScript.Sleep 10 '--------------that make it worst! 
Next '---------------the error appear always at this line---------- 
If Err Then 
    Wscript.Echo Err.Number, Err.Description, Err.Source 
    Set lastErr = CreateObject("WbemScripting.SWbemLastError") 
    Wscript.Echo lastErr.Operation 
End If 
Wscript.Echo "LastIter.: " & cnt 
'-2147023170 
'ExecQuery 
'LastIter.: 2152 or 1592 or 1314 or 959 ... varied random 

WBEMTEST:

enter image description here

附:我用System Restore做了一些測試來測試一個假設,並在上次Windows安全更新前的幾天恢復,並猜測是什麼?現在我得到不同的錯誤:「關閉」。它甚至更困惑,因爲在Undo Last Restore之後,我仍然得到相同的新的錯誤(關閉)。這沒有意義。

+2

事件日誌中的任何內容?您是否使用['WBEMtest'](http://technet.microsoft.com/en-us/library/cc180684.aspx)和/或['WMIDiag'](http://blogs.technet.com/b /askperf/archive/2012/02/03/wmidiag-2-1-is-here.aspx)? – 2013-03-24 08:49:40

+0

感謝您的回覆,我用'WBEMTest'測試過,並且會發布屏幕截圖 – 2013-03-24 23:30:49

+1

您是否嘗試按照[此處]所述修復WMI(http://social.technet.microsoft.com/Forums/en-US/winservergen/thread/8ed26d46 -9994-4052-a307-5b071805aea8)? – 2013-03-25 08:41:06

回答

0

你試過SFC/SCANNOW了嗎? 我沒有看到這涉及到哪個Windows平臺。 XP,Vista,7,8.x,10預覽版? 32位,64位?