VBscript file search

Does anyone know if there is a way through VBscript to search an entire server for any occurance of a ".mdb" file and then write the finding information to an output file showing the name of the file, location, owner, date last accessed, date created, and date modified?

I really appreciate your help or suggestions.
Thanks
tesla764Asked:
Who is Participating?
 
Bill PrewCommented:
Give this a try, save as a VBS script and adjust the starting folder.  Try it on a small subfolder first to get an idea if it's getting the info you want before you run it on a larger drive or share.  It will certainly take a while to search a large drive, no matter what tool you use.

sFolder = "c:\ee"

Set oFSO = WScript.CreateObject("Scripting.FileSystemObject")

DoSearch oFSO.GetFolder(sFolder)

Sub DoSearch(oFolder)
   For Each oFile in oFolder.Files
      If LCase(Right(oFile.Name, 4)) = ".mdb" Then
         WScript.Echo "Name = " & oFile.Name
         WScript.Echo "Path = " & oFile.Path
         WScript.Echo "Owner = " & GetOwner(oFile.Path)
         WScript.Echo "DateLastAccessed = " & oFile.DateLastAccessed
         WScript.Echo "DateCreated = " & oFile.DateCreated
         WScript.Echo "DateLastModified = " & oFile.DateLastModified
         WScript.Echo "-------------------------------------"
      End If
   Next
   For Each oSubFolder In oFolder.Subfolders
      DoSearch(oSubFolder)
   Next
End Sub

Function GetOwner(sFile)
   Set oWMI = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")

   Set cItems = oWMI.ExecQuery("ASSOCIATORS OF {Win32_LogicalFileSecuritySetting='" & sFile & "'} WHERE AssocClass=Win32_LogicalFileOwner ResultRole=Owner")

   For Each oItem in cItems
      GetOwner = oItem.ReferencedDomainName & "/" & oItem.AccountName
   Next
End Function

Open in new window

~bp
0
 
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database ArchitectCommented:
How 'big' is your 'entire server' ?

If I did that here, even with the faster Cray supercomputer, it would probably take a looooong time.

mx
0
 
Rey Obrero (Capricorn1)Commented:
see the codes from this link

http://allenbrowne.com/ser-59.html

0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
Jeffrey CoachmanMIS LiasonCommented:
...MX,
...isn't the "Owner" of the DB is something you would have to open the db file to determine....
(making this a bit more complex)
0
 
tesla764Author Commented:
Beautiful!! That's exactly what I was looking for.
Thanks!!!
0
 
Bill PrewCommented:
Welcome, glad that helped, thanks for the feedback.

~bp
0
 
tesla764Author Commented:
Thanks!!
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.