Link to home
Start Free TrialLog in
Avatar of sirbounty
sirbountyFlag for United States of America

asked on

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

Avatar of Jared Luker
Jared Luker
Flag of United States of America image

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?
Avatar of sirbounty

ASKER

It's running locally, yes...
And it works fine on some computers, but not on others?
correct
SOLUTION
Avatar of RobSampson
RobSampson
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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...
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.
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.
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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...
turn off option explicit or make sure that every single variable you are using has been DIMed
Not using it...
Your original code has Option Explicit on line 1.  Did you remove it?
Oh - maybe I misunderstood.
With option explicit - nothing is flagged as undeclared.
How does removing it help (it's not in the current code).
It was just a troubleshooting/debugging suggestion.

If the script continues without it, then there is something that is missing somewhere.
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...
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

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?
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?

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

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...
Avatar of rkorinek
rkorinek

Have you tried limiting your returned recordset to forward only?  For example..

Set colFiles = objWMIService.ExecQuery _
    ("Select * From CIM_DataFile Where Extension = 'mdb'",,48)
Thought my original script did, but I just tried it and again it fails with the rpc error...weird...
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.
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
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

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

If memory serves me, it was erroring out on the count property...I can get the exact error tomorrow though.
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.
Oddly enough though,
the wbemtest method worked...it returned 96 objects from drive G.  Weird, huh?
ah, but it doesn't without the drive filter... :(
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).
Hi, that's not a bad idea...what happens if you recreate the admin share on the offending drive?  Does the IPC$ exist?

Rob.
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...
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.
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'")