我在询问之前搜索并没有找到适用于我的代码的任何内容。我尝试过的也在代码中进行了注释。错误 800706BE(远程过程调用失败)出现在For..Next
循环中,并且每次都会以不同的随机迭代次数打破循环。我想念什么以及如何修复该(简单)代码?
'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
WBEM测试:
PS我做了一些测试System Restore
来测试一个假设并在上次 Windows 安全更新前几天恢复,你猜怎么着?现在我得到不同的错误:80041033 “正在关机”。之后更加困惑Undo Last Restore
,我仍然收到相同的新错误(正在关闭)。这已经没有意义了。