I search before ask and not find anything applicable to my code. Also what I tried is commented in the code. The error 800706BE (The remote procedure call failed) appear in For..Next
loop and each time break the cycle at varied random amount of iterations.
What I miss and how to fix that (simple) code?
'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:
P.S. I did some test with System Restore
to test one hypothesis and restore a few days back before last Windows security update, and guess what? Now I get different error: 80041033 "Shutting down". It's even more confused as after Undo Last Restore
, I still get the same new error (Shutting down). This has not sense.