如何获取具有ProductName和ProductVersion的DLL的目录列表?

时间:2008-12-01 19:58:16

标签: dos

当我在Windows资源管理器中查看目录时,我可以看到该目录中DLL的ProductName和ProductVersion属性。

我需要将带有ProductName和ProductVersion的DLL列表导出到文本文件中。

如果我c:\>dir *.dll > test.log,则test.log没有ProductName和ProductVersion。

有人可以帮助我将这些属性与文件名一起导出到文件中吗?

即使它是免费软件工具或其他dir开关,也会很有用。

6 个答案:

答案 0 :(得分:2)

PowerShell在这里是你的朋友 - 它可以从微软免费获得(如在啤酒中)。

以下是一个内容,将windows目录中所有dll的产品名称,产品版本和文件名吐出到test.log中:

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

好的,所以它是一个行 - 但在命令提示符下它仍然只有一行

PowerShell afficionados可能会进一步压缩上述内容。请注意,PowerShell允许我们从命令行使用.Net基类库(甚至是您自己的程序集),例如 System.Diagnostics.FileVersionInfo

如果您尚未使用PowerShell,那么您可以在商店中享受一种享受 - 特别是如果您是.Net开发人员:)

答案 1 :(得分:1)

使用VBScript,您可以执行以下操作:

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

答案 2 :(得分:1)

使用.NET应用程序可以非常轻松地完成此操作。

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);

    }
}

显然,您必须添加一个检索指定目录中所有文件的函数。

答案 3 :(得分:1)

将VB.Net版本添加到列表中:

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

通过以下方式调用:CreateLog(“c:\ log.txt”,“c:\ windows”,“* .dll”)

编辑:添加了搜索模式。

答案 4 :(得分:0)

我根本不能说这个软件,但这似乎可以满足您的需求:

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

答案 5 :(得分:0)

有趣的是,我不知道这个GetDetailsOf函数 我想知道任意大小......
我不确定什么是限制,这似乎在文件夹或至少用户设置之间有所不同,所以我做了一些更灵活的事情:

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

要回答这个问题,您可以检查detail何时等于您要查找的信息,并仅显示这些值。

相关问题