Option Explicit
Dim wmiService, fileList, file
Dim dirName, machine
dirName = "C:\Windows\System32"
machine = "."
Set wmiService = GetObject( "winmgmts:\\" & machine & "\root\cimv2")
Set fileList = wmiService.ExecQuery ( "ASSOCIATORS OF {Win32_Directory.Name=’" & dirName & "’} Where ResultClass = CIM_DataFile" )
For Each file In fileList
If file.Extension = "dll" Then
Print file.FileName & ".dll; version: " & file.Version
End If
Next
the immediately solution is by using a WMI script. Admittedly, we could have achieved the same results by using the FileSystemObject.
We opted to go with WMI for one simple reason: that enables us to run this script against remote computers.
(By contrast, the FileSystemObject pretty much limits us to working with the local computer.) Need to get file information off a remote computer named atl-fs-01? No problem; all you have to do is take the preceding script and change line 1 to look like this:
machine = "at1-fs-01"
The script itself starts off by connecting to the WMI service on the local computer.
Set fileList = wmiService.ExecQuery ( "ASSOCIATORS OF {Win32_Directory.Name=’" & dirName & "’} Where ResultClass = CIM_DataFile" )
It’s not pretty, but this is how you retrieve a collection of all the files in a specified folder (in this case, C:\Windows\System32).
Basically what we’re saying here is this: "Bring me back all the CIM_DataFile objects associated with the directory named C:\Windows\System32." Because CIM_Datafile is the WMI class that represents files. the query simply brings back a collection of all the files found in C:\Windows\System32. What if you wanted a collection of all the files found in D:\Test? In that case you’d modify the dirName variable.
machine = "D:\Test"
Once we have our collection we set up a For Each loop to walk us through each item (each file) in the collection. Inside that loop we use this line of code to check the value of the Extension property:
If file.Extension = "dll" Then
If Extension is equal to DLL(note that this is just the three letters DLL, without a dot; don’t include the dot when specifying the file extension in WMI) we then use this line of code to echo back the Name and Version.
Print file.FileName & ".dll; version: " & file.Version
And what if the file extension isn’t equal to dll? No problem; in that case we just loop around and repeat the process with the next item in the collection.Of course the output can be very diverse and varied ( i.e. text file, DataTable )
Based on "How Can I Get a List of All the .dll Files in a Folder, Along with Their Version Numbers? " from the Scripting Guys.
Posted in WMI


daniva




Recent Comments