3

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

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

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

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

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

4

6 回答 6

2

PowerShell是你的朋友——它可以从微软免费获得(就像在啤酒中一样)。

下面是一条将windows目录下所有dll的产品名称、产品版本和文件名吐到test.log中的一行代码:

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

好的,所以这是一条很长的行 - 但它仍然只是命令提示符下的一行

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

如果您还没有玩过 PowerShell,那么您可以在商店中获得一种享受 - 特别是如果您是 .Net 开发人员 :)

于 2008-12-01T20:57:44.523 回答
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
于 2008-12-01T20:02:15.010 回答
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);

    }
}

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

于 2008-12-01T20:10:22.810 回答
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")

编辑:添加了搜索模式。

于 2008-12-01T20:24:52.873 回答
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
于 2008-12-01T20:06:59.010 回答
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等于您要查找的信息并仅显示这些值。

于 2008-12-01T21:43:59.140 回答