Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Limitation on CIM_Datafiles During Media File Search?

Status
Not open for further replies.

LeeAdams

Technical User
Feb 22, 2008
3
0
0
GB
Hi everyone,

I created the following vbscript code to search remote pc's/servers on our network for media files by looking for file extentions. The script works fine on all PCs and some servers, yet if I scan a server with over 1Tb of disk space the script runs but doesn't seem to produce an output file. Is there any limitations on the amount of data these script can process? or does anyone have any better suggestions on how to search for these files?

Thanks in advance, Lee.

Here is the code,

Option Explicit
'this subroutine creates and arranges the text file
Sub writeToLogFile(strLogFile, strLogMessage)
Dim objFso, objLogFile
Set objFso = CreateObject("Scripting.FileSystemObject")
Set objLogFile = objFso_OpenTextFile(strLogFile, 8, True)
objLogFile.WriteLine(strLogMessage)
objLogFile.Close
Set objLogFile = Nothing
Set objFso = Nothing
End Sub
Dim strServerName
'this prompts the user for an input
strServername=InputBox("Which server do you want to search for media files? ","newmediafilecheck.vbs","Servername")
'specify the output location for the results
Dim strMediaFilesFound, arrDates, strDebugLog
arrDates = split(Date, "/")
strMediaFilesFound = "C:\" & ucase(strServername) & "_" & "MediaFilesReport" & arrDates(2) & arrDates(1) & arrDates(0) & Replace(Time, ":", "") & ".txt"
strDebugLog = "C:\" & ucase(strServername) & "_" & "DebugLogReport" & arrDates(2) & arrDates(1) & arrDates(0) & Replace(Time, ":", "") & ".txt"
'if nothing is entered the script ends
If strServername="Servername" Then
wscript.echo "Nothing entered or you cancelled"
wscript.quit
End If
'if cancelled then script aborts
If strServername = "" Then
'~ "" = no, so abort with a message:
MsgBox "OK, Aborting.", 64, "MediaFileCheck.vbs"
WScript.Quit
End If
' Dim objItem, colItems, strComputer, SumFiles
' object to represetn WMI interface on server:
Dim objWMIService
' Instantiate WMI object on target server, handle and report any errors:
On Error Resume Next
Set objWMIService = GetObject("winmgmts:\\" & strServername & "\root\cimv2")
If Err.Number <> 0 Then
writeToLogFile strDebugLog, "Can't connect to WMI interface on " & strServername
wscript.echo "Can't connect to WMI interface on " & strServername
wscript.quit
End If
On Error Goto 0
' Collection to hold list of local disks on server:
Dim colDisks
' Get a list of physical volumes on the server:
'Set colDisks = objWMIService.ExecQuery("SELECT * FROM Win32_LogicalDisk WHERE DriveType=3")
'this is the file extensions the script will search for:
Dim arrExtensions
arrExtensions = Array("mp3","vob","mp4","wma","mov","aac","wav","mpeg","3gp","midi","avi","mpg","wmv")
' Variable to use to go through arrExtensions
Dim strExtension
For Each strExtension In arrExtensions
' Collection to hold list of qualifying files:
Dim colFileList
Set colFileList = objWMIService.ExecQuery("SELECT Name,FileSize FROM CIM_Datafile WHERE Extension = '" & strExtension & "'")
' Variable to go through colFileList:
Dim objFile
For Each objFile In colFileList
writeToLogFile strMediaFilesFound, "\\" & strServername & "\" & Replace(objFile.name, ":", "$") & vbTab & Round(objFile.FileSize / 1024 / 1024, 2) & "Mb"
Next
Set colFileList = Nothing
Next

' clean up

'Next
Set objWMIService = Nothing
MsgBox "Script complete.", 64, "MediaFilesSearch.vbs"
 
I'm not sure if there is a limitation to the CIM_DataFile class, but I would recommend the following....

1. Rather than query for each extension type separately...change the query to find them all at once
2. I've noticed that sometimes if you select everything rather than specific properties it is sometimes as fast or faster
3. Change the query to return immediately....

Here's an example of what I've mentioned...........
Code:
Option Explicit

Dim arrExtensions : arrExtensions = Array("'mp3'","'vob'","'mp4'","'wma'","'mov'", _
                                         "'aac'","'wav'","'mpeg'","'3gp'","'midi'", _
                                         "'avi'","'mpg'","'wmv'")
Dim strQueryFilter : strQueryFilter = "Extension = " & Join(arrExtensions, " OR Extension = ")

Dim strComputer : strComputer = "."
Dim objWMIService : Set objWMIService = GetObject("winmgmts:\\" & _
                       strComputer & "\root\cimv2")
Dim colFiles : Set colFiles = objWMIService.ExecQuery("SELECT * FROM CIM_DataFile WHERE " & strQueryFilter,, 48)
Dim objFile
For Each objFile In colFiles
   WScript.Echo objFile.Name & vbTab & objFile.FileSize
Next

--------------------------------------------------------------------------------
dm4ever
My philosophy: K.I.S.S - Keep It Simple Stupid
 
Hi dm_4ever,

Thanks for your reply, I've added the code as suggested but I still get an error

Line 48
Char 1
The Remote Procedure Call Failed
800706BE
Source (null)

Which points to the line

For Each objFile In colFiles

Any ideas?

Thanks
Lee
 
I've never run into a limitation per se. However I would not be at all suprised to find that you are simply running out of physical memory on the machine that is running the script. Run the script and watch memory consumption.


[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top