CIM_Datafile remote procedure call failed

I have some code to scan our servers for mdb files - it works on most of them, but a few are failing and I've been able to gather as much as:
The remote procedure call failed.
when it gets to the loop:   For Each objFile in colFiles

It's like the collection isn't properly initialized, although I know that these files exist...any ideas what could be causing the problem - seems to exist on about 1/3 of my servers...
Option Explicit
Dim strComputer : strComputer = "."
Dim objFSO : Set objFSO = CreateObject("Scripting.FileSystemObject")
Dim objWMI : Set objWMI = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
 
Dim colSet : Set colSet = objWMI.ExecQuery ("Select * From Win32_ComputerSystem")
Dim objItem, strSrvName
 
For each objItem in colSet
  strSrvName = objItem.Name
Next
 
Set colSet=Nothing
 
Dim objOut : Set objOut = objFSO.CreateTextFile("E:\Batch\" & strSrvName & "-db.xls")
objOut.Writeline "SERVER NAME" & vbtab & "CREATION" & vbTab & "ACCESSED" & vbtab & "MODIFIED" & vbTab & "FILE NAME" & vbtab & "FILE SIZE" & vbTab & "FULL PATH" & vbtab & "OWNER"
Dim colFiles:Set colFiles = objWMI.ExecQuery ("Select * from CIM_Datafile Where Extension ='mdb'")
ScanFiles (colFiles)
objOut.Close
Set objOut = Nothing
Set objWMI = Nothing
Set objFSO = Nothing
Set colFiles = Nothing
wscript.quit 
 
Sub ScanFiles (colFiles)
Dim objFile, strFileName, strOwner
  For Each objFile in colFiles
  On Error Resume Next
    strFIleName=LCase(objFile.Name)
      Dim colOwner:Set colOwner = objWMI.ExecQuery ("ASSOCIATORS OF {Win32_LogicalFileSecuritySetting=""" & Replace(objFile.Name, "\", "\\") & """}" & " WHERE AssocClass=Win32_LogicalFileOwner ResultRole=Owner")
      If Err.Number <> 0 Then objOut.WriteLine & Err.Number & ":" & Err.Description & vbTab & strFileName
      For Each objItem in colOwner
        strOwner = objItem.ReferencedDomainname & "\" & objItem.Accountname
        If Err.Number <> 0 Then objOut.WriteLine  Err.Number & ":" & Err.Description & vbTab & strFileName
      Next
      If strOwner="\" then strOwner="None Found"
      objOut.WriteLine strSrvName & vbTab & DateStringToDate(objFile.CreationDate) & vbTab & DateStringToDate(objFile.LastAccessed) & _
           vbTab & DateStringToDate(objFile.LastModified) & vbTab & objFile.FileName & "." & objFile.Extension & vbTab & FormatNumber(objFile.FileSize, 0, -1,, -1) & _
           vbTab & objFile.Name & vbTab & strOwner & " ")
        If Err.Number <> 0 Then objOut.WriteLine Err.Number & ":" & Err.Description & vbTab & strFileName
    On Error Goto 0
  Next
  On Error Goto 0
  objOut.WriteLine "Scan Complete"
End Sub

Open in new window

LVL 67
sirbountyAsked:
Who is Participating?
 
rkorinekCommented:
Are  you on a large file server?  I have run into this problem when WMI runs out of memory processing a query that returns a large amount of data.  Unfortunately, I have not been able to find a method to manage the memory any better than a forward only recordset.
0
 
Jared LukerCommented:
If you are running the script locally on the machine that your scanning, it should have nothing to do with RPC.  Am I missing something?
0
 
sirbountyAuthor Commented:
It's running locally, yes...
0
Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

 
Jared LukerCommented:
And it works fine on some computers, but not on others?
0
 
sirbountyAuthor Commented:
correct
0
 
RobSampsonCommented:
Hi sirbounty,

My guess is that it may be trying to access a drive that is unavailable.  I can't remember if CIM_DataFile is capable of scanning network drives that might happen to be mapped, but, let's try restricting it to a specific drive or two.....this will scan drives c and d....

Regards,

Rob.
Option Explicit
Dim strComputer : strComputer = "."
Dim objFSO : Set objFSO = CreateObject("Scripting.FileSystemObject")
Dim objWMI : Set objWMI = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
 
Dim colSet : Set colSet = objWMI.ExecQuery ("Select * From Win32_ComputerSystem")
Dim objItem, strSrvName
 
For each objItem in colSet
  strSrvName = objItem.Name
Next
 
Set colSet=Nothing
 
Dim objOut : Set objOut = objFSO.CreateTextFile("E:\Batch\" & strSrvName & "-db.xls")
objOut.Writeline "SERVER NAME" & vbtab & "CREATION" & vbTab & "ACCESSED" & vbtab & "MODIFIED" & vbTab & "FILE NAME" & vbtab & "FILE SIZE" & vbTab & "FULL PATH" & vbtab & "OWNER"
Dim colFiles:Set colFiles = objWMI.ExecQuery ("Select * from CIM_Datafile Where (Drive='c:' Or Drive='d:') And Extension ='mdb'")
ScanFiles (colFiles)
objOut.Close
Set objOut = Nothing
Set objWMI = Nothing
Set objFSO = Nothing
Set colFiles = Nothing
wscript.quit 
 
Sub ScanFiles (colFiles)
Dim objFile, strFileName, strOwner
  For Each objFile in colFiles
  On Error Resume Next
    strFIleName=LCase(objFile.Name)
      Dim colOwner:Set colOwner = objWMI.ExecQuery ("ASSOCIATORS OF {Win32_LogicalFileSecuritySetting=""" & Replace(objFile.Name, "\", "\\") & """}" & " WHERE AssocClass=Win32_LogicalFileOwner ResultRole=Owner")
      If Err.Number <> 0 Then objOut.WriteLine & Err.Number & ":" & Err.Description & vbTab & strFileName
      For Each objItem in colOwner
        strOwner = objItem.ReferencedDomainname & "\" & objItem.Accountname
        If Err.Number <> 0 Then objOut.WriteLine  Err.Number & ":" & Err.Description & vbTab & strFileName
      Next
      If strOwner="\" then strOwner="None Found"
      objOut.WriteLine strSrvName & vbTab & DateStringToDate(objFile.CreationDate) & vbTab & DateStringToDate(objFile.LastAccessed) & _
           vbTab & DateStringToDate(objFile.LastModified) & vbTab & objFile.FileName & "." & objFile.Extension & vbTab & FormatNumber(objFile.FileSize, 0, -1,, -1) & _
           vbTab & objFile.Name & vbTab & strOwner & " ")
        If Err.Number <> 0 Then objOut.WriteLine Err.Number & ":" & Err.Description & vbTab & strFileName
    On Error Goto 0
  Next
  On Error Goto 0
  objOut.WriteLine "Scan Complete"
End Sub

Open in new window

0
 
sirbountyAuthor Commented:
Hey Rob - I can give it a try tomorrow, but I did have a prior version where I built a dictionary of just the local volumes.  I've since stripped that out, but hey - could be that I shot myself in the foot doing so...
0
 
RobSampsonCommented:
Maybe....can't quite remember.....also, where you have
Select * from CIM_Datafile

maybe change that to
Select Name from CIM_Datafile

so it doesn't pull too much data....

Regards,

Rob.
0
 
sirbountyAuthor Commented:
With those changes, I get
The remote procedure call failed.
when iterating the collection (for each...)
and when trying to simply display the count property of the collection, returns:
 SWbemObjectSet: The remote procedure call failed.
0
 
RobSampsonCommented:
Hmmm, strange....you said you're sure that there are MDB files there?

OK, so after this line:
Dim colFiles:Set colFiles = objWMI.ExecQuery ("Select * from CIM_Datafile Where (Drive='c:' Or Drive='d:') And Extension ='mdb'")


if you put
WScript.Echo TypeName(colFiles)

what value do you get?

On my system, the value is SWbemObjectSet whether the collection returns files or not....

And this does not cause an error when the query does not return any files, so I think the actualy error must be with the ExecQuery line that runs the query.....

If the following process still fails, then I'd say there's some WMI problem on the local computer...

Start - Run and type WBEMTest
Click connect
Assuming you are on the computer you want to search enter root\cimv2 in the namespace
Click Connect
Click Query
Paste this query into the box:
Select * from CIM_DataFile where Drive='C:' AND Extension = 'mdb'

and see what you get....

Rob.
0
 
sirbountyAuthor Commented:
Putting in some more tests, my output is now producing 3 instances of this error (with no other output):

424: Object Required

(in response to    If Err.Number <> 0 Then objOut.WriteLine Err.Number & ":" & Err.Description)
but objFile.Name appears to be blank..

msgbox " "
msgbox objFile.Name
msgbox " "

I only get the first and last msgbox popus...
0
 
Jared LukerCommented:
turn off option explicit or make sure that every single variable you are using has been DIMed
0
 
sirbountyAuthor Commented:
Not using it...
0
 
Jared LukerCommented:
Your original code has Option Explicit on line 1.  Did you remove it?
0
 
sirbountyAuthor Commented:
Oh - maybe I misunderstood.
With option explicit - nothing is flagged as undeclared.
How does removing it help (it's not in the current code).
0
 
Jared LukerCommented:
It was just a troubleshooting/debugging suggestion.

If the script continues without it, then there is something that is missing somewhere.
0
 
sirbountyAuthor Commented:
with opt exp, it did flag one undeclared item inside my loop/sub, but I corrected that.
It runs fine either way - but still returns the 3 object required errors noted above...
0
 
sirbountyAuthor Commented:
Okay, I started back at square one and just tried the attached script.

It failed after a few moments with:

test.vbs(8, 1) (null): The remote procedure call failed.
strComputer = "."
 
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
 
Set colFiles = objWMIService.ExecQuery _
    ("Select * From CIM_DataFile Where Extension = 'mdb'")
 
For Each objFile in colFiles
    Wscript.Echo objFile.Name
Next

Open in new window

0
 
sirbountyAuthor Commented:
Hmm - limiting it to drive C seems to work...but all mdb files on that drive are irrelevant...Must be something wrong with the ones on the drive I'm needing...any idea what it could be or how to track it down?
0
 
Jared LukerCommented:
I'm not sure why you would be getting an RPC error on line 8 of the script above.  You are setting strComputer to "." (local) so it should not be trying to go over the network.  Weird stuff.

Since there is no need for RPC when you are dealing with files locally, that is probably why checking files on drive C works.

 How about mapping a drive to the location you are trying to work with and then using the mapped drive letter in the script instead of a remote WMI call?

0
 
RobSampsonCommented:
SirBounty, I'm not sure why this is happening either, but perhaps a workaround would be to parse the output of a DIR command?

Rob.
Set objShell = CreateObject("WScript.Shell")
strDrive = "D:"
strFileName = "*"
strExt = ".mdb"
strOutputFile = "FileList.txt"
strCommand = "cmd /c dir /s /b " & strDrive & strFileName & strExt & " > " & strOutputFile
objShell.Run strCommand, 0, True
Set objFSO = CreateObject("Scripting.FileSystemObject")
Const intForReading = 1
Set objFile = objFSO.OpenTextFile(strOutputFile, intForReading, False)
If Not objFile.AtEndOfStream Then
	arrFiles = Split(objFile.ReadAll, VbCrLf)
	objFile.Close
	Set objFile = Nothing
	objFSO.DeleteFile strOutputFile, True
	strDetails = Join(arrfiles, vbCrLf)
Else
	strDetails = "No files were found from the command" & VbCrLf & strCommand
End If
WScript.Echo strDetails

Open in new window

0
 
sirbountyAuthor Commented:
Hey gang - I'm not looking for a workaround as it would add a good deal more for subsequent processing (getting owner, file dates, etc).
Plus, I hate for something to beat me :^)
I'm currently narrowing the selection criteria to the four main parent folders and will continue weeding it down until I discover the culprit...
0
 
rkorinekCommented:
Have you tried limiting your returned recordset to forward only?  For example..

Set colFiles = objWMIService.ExecQuery _
    ("Select * From CIM_DataFile Where Extension = 'mdb'",,48)
0
 
sirbountyAuthor Commented:
Thought my original script did, but I just tried it and again it fails with the rpc error...weird...
0
 
rkorinekCommented:
I still think you root problem is the size of the query.  I have gotten RPC errors when running large queries on large file servers.  Are the server all of the same size data wise?  This would also explain why your code runs fine on some servers, but not all of them.
0
 
sirbountyAuthor Commented:
tough to say - but most are configured the same - I'll look deeper into it tomorrow to see if the failing ones show any similar setups
0
 
RobSampsonCommented:
What does this give you?

Rob.
strComputer = "."
 
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
 
Set colFiles = objWMIService.ExecQuery _
    ("Select * From CIM_DataFile Extension = 'mdb'")
 
If colFiles.Count > 0 Then
	WScript.Echo "Files were found..."
	For Each objFile in colFiles
	    Wscript.Echo objFile.Name
	Next
Else
	WScript.Echo "No files were found."
End If

Open in new window

0
 
RobSampsonCommented:
Ooops, missed the WHERE....
strComputer = "."
 
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
 
Set colFiles = objWMIService.ExecQuery _
    ("Select * From CIM_DataFile WHERE Extension = 'mdb'")
 
If colFiles.Count > 0 Then
	WScript.Echo "Files were found..."
	For Each objFile in colFiles
	    Wscript.Echo objFile.Name
	Next
Else
	WScript.Echo "No files were found."
End If

Open in new window

0
 
sirbountyAuthor Commented:
If memory serves me, it was erroring out on the count property...I can get the exact error tomorrow though.
0
 
sirbountyAuthor Commented:
Sorry for the delay Rob - that doesn't work either.  It also gives me remote procedure call failed...

But, I've given up - need to get rolling on this, so I'm moving to a slower recursive drive/folder loop to accomplish this.
Thanx for the attempts.
0
 
sirbountyAuthor Commented:
Oddly enough though,
the wbemtest method worked...it returned 96 objects from drive G.  Weird, huh?
0
 
sirbountyAuthor Commented:
ah, but it doesn't without the drive filter... :(
0
 
sirbountyAuthor Commented:
I went with the recursive fso solution...thanx for the help just the same.
I suspect that it's got more to do with permission problems where users have stripped admin & system rights from their folder.  I'll be testing that shortly and will post back, if that's the case...(the fso script does reveal some folders as permission denied on one of these servers).
0
 
RobSampsonCommented:
Hi, that's not a bad idea...what happens if you recreate the admin share on the offending drive?  Does the IPC$ exist?

Rob.
0
 
sirbountyAuthor Commented:
recreate the admin share?  Not sure I follow...ipc$ does exist.
I thought it might be permissions, since the fso method found some problems, but I'm still not 100% certain, since there's one file that I couldn't alter - probably in use...
0
 
RobSampsonCommented:
It's a fairly long shot.....but open Computer Management, go to System Tools --> Shared Folders --> Shares, and Stop Sharing the C$ share.  Then restart the Server services in Services and Applications.

It is definately a very strange problem......

Rob.
0
 
i134786pCommented:
I had the same problem. adding the Drive = 'c:' fixes the problem.

Doesnt work: ("Select * from CIM_DataFile Where FileName = 'notepad'")

Doesnt work: ("Select * from CIM_DataFile Where FileName = 'notepad' and Drive = 'c'")

works!!!: ("Select * from CIM_DataFile Where Drive = 'c:' and FileName = 'notepad'")
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.