tags:

views:

656

answers:

6

When I look at a directory in Windows Explorer, I can see a ProductName and ProductVersion property for the DLL's in that directory.

I need to export this DLL list with ProductName and ProductVersion into a text file.

If I do c:\>dir *.dll > test.log, the test.log does not have the ProductName and ProductVersion.

Could someone help me to get these properties exported to a file along with the filename?

Even if it is a freeware tool or some other dir switch, that will be useful.

+1  A: 

Using VBScript you could do the following:

Set objShell = CreateObject ("Shell.Application")
Set objFolder = objShell.Namespace ("C:\Scripts")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Dim arrHeaders(40)

For i = 0 to 40
    arrHeaders(i) = objFolder.GetDetailsOf (objFolder.Items, i)
Next

For Each strFileName in objFolder.Items
    For i = 0 to 40
        Wscript.echo arrHeaders(i) & ": " & objFolder.GetDetailsOf (strFileName, i) 
    Next
    Wscript.Echo
Next
0xA3
A: 

I cannot speak to this software at all, but this appears to do what you're looking for:

http://www.softpedia.com/get/Programming/Other-Programming-Files/STRFINFO.shtml

SYNTAX
~~~~~~
StrFInfo[.EXE] ExeDllOcxFileName  [Property1  [Property2 ...]]

COMMON PROPERTIES
~~~~~~~~~~~~~~~~~
FileDescription  FileVersion InternalName
OriginalFileName ProductName ProductVersion
CompanyName LegalCopyRight $Translation
Patrick Harrington
+1  A: 

You can do this fairly easily with a .NET application.

using System;
using System.Diagnostics;

static class MainClass
{
    static void Main(string[] args)
    {

        FileVersionInfo info = FileVersionInfo.GetVersionInfo("c:\\test.txt");

        // Display version information.
        Console.WriteLine("Checking File: " + info.FileName);
        Console.WriteLine("Product Name: " + info.ProductName);
        Console.WriteLine("Product Version: " + info.ProductVersion);
        Console.WriteLine("Company Name: " + info.CompanyName);

    }
}

Obviously, you'd have to add a function that retrieved all the files in a specified directory.

Andrew Flanagan
I like this solution - I would suggest having the code take in a source DLL file path, and a log file path, and then have a batch file execute it and give him the versatility to just adjust the batch file as for which files he wants to pick up.
Patrick Harrington
+1  A: 

Adding a VB.Net version to the list:

Sub CreateLog(ByVal Logfile As String, ByVal PathToLog As String, Optional ByVal SearchPattern As String = "*.*")

    Dim FileInfo As FileVersionInfo
    Dim ret As String = ""
    For Each File As String In IO.Directory.GetFiles(PathToLog, SearchPattern)
        FileInfo = FileVersionInfo.GetVersionInfo(File)
        If FileInfo.ProductName & FileInfo.ProductVersion <> "" Then
            ret &= FileInfo.ProductName & ", " & FileInfo.ProductVersion & vbCrLf
        End If
    Next

    IO.File.WriteAllText(Logfile, ret)

End Sub

Call it by: CreateLog("c:\log.txt", "c:\windows", "*.dll")

Edit:Added searchpattern.

Stefan
I have no clue to why all my code examples has a #¤%#-up color syntax...
Stefan
I think it's because it interpreted the backslash in C:\ as escaping the quote, thus the string literal is unterminated. I dunno if VB does escaping that way, but if it does, then it's an error in your code and not just the StackOverflow parser :)
rmeador
Its not an error in my code, I have run it. ;)
Stefan
+1  A: 

PowerShell is your friend here - and it's freely (as in beer) available from Microsoft.

The following is a one liner to spit out the product name, product version and file name of all the dlls in the windows directory into test.log:

dir c:\windows\*.dll | % {[System.Diagnostics.FileVersionInfo]::GetVersionInfo($_)} | % { $_.ProductName + ", " + $_.ProductVersion + ", " + $_.FileName} > test.log

OK, so it's a long line - but it is still just one line at the command prompt.

PowerShell afficionados will probably be able to condense the above still further. Note that PowerShell allows us to use the .Net base class library (or even your own assemblies) such as System.Diagnostics.FileVersionInfo from the command line!

If you haven't played with PowerShell yet, you have a treat in store - particularly if you are a .Net developer :)

Dan Blanchard
A: 

Interesting, I didn't know this GetDetailsOf function.
I wondered about the arbitrary size...
I am not sure what is the limit, which seem to vary between folders or at least user settings or something, so I made something more flexible:

Set shell = CreateObject("Shell.Application")
Set folder = shell.Namespace("D:\Documents")

Set fso = CreateObject("Scripting.FileSystemObject")
For Each fileName in folder.Items
  i = 0
  emptyNb = 0
  Do
    detail = folder.GetDetailsOf(folder.Items, i)
    If detail = "" Then
      emptyNb = emptyNb + 1
    Else
      detailValue = folder.GetDetailsOf(fileName, i)
      If detailValue <> "" Then
        Wscript.Echo i & " " & detail & ": " & detailValue
      End If
      emptyNb = 0
    End If
    i = i + 1
  Loop While emptyNb < 3 ' Arbirary, adjust as you see fit
  detailValue = folder.GetDetailsOf(fileName, -1)
  If detailValue <> "" Then
    Wscript.Echo "Tooltip:" & vbCrLf & detailValue
  End If
  Wscript.Echo
Next

To answer the question, you can check when detail is equal to the info you are looking for and only display these values.

PhiLho