查找给定目录下的 Dll 和 Exe






1.29/5 (9投票s)
2007年8月21日
4分钟阅读

16797

151
File_Version 是一个用 C#.Net 开发的简单工具。它可以为您获取所选目录下的所有 Dll 和 EXE 信息。很多时候,我们可能需要了解特定产品随附安装的 Dll/Exe 的信息。
File_Version 是一个用 C#.Net 开发的简单工具。它可以为您获取所选目录下的所有 Dll 和 EXE 信息。很多时候,我们可能需要了解特定产品随附安装的 Dll/Exe 的信息。此工具将为您提供这些信息。它将获取 Dll Ex 的各种参数
一旦我们有了这个 XML,我们就可以编写自己的 XSLT 将其转换为任何我们想要的格式。我编写了一个 XSLT,可以将输出的 XML 转换为 HTML 页面。一旦它找到了给定目录中所有 DLL 或 EXE 的信息,它就会以 XML 和 HTML 文件输出。另一个显著的特点是 DLL 的逐个版本比较。每次它都会将输出信息写入带有系统日期和时间戳的 XML/HTML 文件。这将帮助我们存储带有日期和时间戳的信息。因此,我们可以比较以前和当前找到的 dll 信息。
该工具的主要特点
1) 它提供了一个简单的用户界面来浏览和选择任何特定文件夹。
2) 它递归地搜索目录中的所有文件,包括嵌套目录
3) 以 XML 格式提供完整的 DLL\EXE 信息
4) 提供 XSLT,可以根据需要轻松修改,将其转换为 HTML 文件格式
5) 使用当前的系统日期和时间作为输出文件名约定。因此可以存储多个文件作为比较的存储库。
6) 您可以选择任何您想要存储文件的输出路径
7) 源代码是用 C#.Net 编写的。您可以根据需要修改代码。它已附加在文件夹中
必备组件
.Net Framework 2.0 需要已安装
如何使用
1) 将 dllhtml.xsl 文件(在附加的 ZIP 文件中)复制到您的 C: 驱动器
2) 打开文件夹并单击“File_Version.EXE”文件
3) 然后它将打开如下所示的用户界面,单击“浏览”按钮选择要搜索的目录
4) 选择您希望输出文件放置的输出目录
5) 点击“点击”按钮。
6) 然后会生成两个输出文件。一个为“<系统日期时间>_dll_exe.xml”和一个“<系统日期时间>_dll_exe.Html”
导出到输出文件后,它会打开源代码 zip 中附加的输出 html 文件
好的,下面是源代码
使用代码
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;
using System.IO;
using System.Xml;
using System.Xml.Xsl;
using System.Xml.Schema;
using System.Xml.Serialization;
using System.Windows;
namespace File_version
{
public partial class Form1 : Form
{
private List<string> dirList = new List<string>();
private string XML_File_Path;
static string HTML_File_Path;
static string path_str;
public Form1()
{
InitializeComponent();
}
[STAThread]
static void
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
List<string> GetAllDirectories(string rootDirectory)
{
dirList.Add(rootDirectory);
DirectoryInfo di = new DirectoryInfo(rootDirectory);
foreach (DirectoryInfo dir in di.GetDirectories())
{
dirList.Add(dir.FullName.ToString());
if (dir.GetDirectories().Length > 0)
{
GetAllDirectories(dir.FullName.ToString());
}
}
return dirList;
}
private void button1_Click(object sender, EventArgs e)
{
try
{
string main_directory = File_Text.Text.ToString();
List<string> directory = this.GetAllDirectories(main_directory);
path_str = DateTime.Now.Day + "_"+ DateTime.Now.Month+ "_" + DateTime.Now.Year + "_"+ DateTime.Now.Hour + "_" + DateTime.Now.Minute + "_" + DateTime.Now.Second;
XML_File_Path = output_folder.Text.ToString()+ path_str + "dll_Exe.xml";
HTML_File_Path = output_folder.Text.ToString() + path_str + "dll_Exe.Html";
XmlTextWriter tw = new XmlTextWriter(XML_File_Path, null);
tw.Formatting = Formatting.Indented;
tw.WriteStartDocument();
tw.WriteStartElement("dll_exe_Info");
foreach (string str_dir in directory)
{
DirectoryInfo di = new DirectoryInfo(str_dir);
FileInfo[] FiArr = di.GetFiles();
int i = 0;
while (i < FiArr.Length)
{
if ((FiArr[i].Extension == ".dll") || (FiArr[i].Extension == ".exe"))
{
tw.WriteStartElement("File", null);
FileVersionInfo myFileVersionInfo = FileVersionInfo.GetVersionInfo(FiArr[i].FullName);
tw.WriteElementString("Name", FiArr[i].Name);
tw.WriteElementString("Description", myFileVersionInfo.FileDescription);
tw.WriteElementString("Version", myFileVersionInfo.FileVersion);
tw.WriteElementString("Fullpath", FiArr[i].FullName);
tw.WriteElementString("Language", myFileVersionInfo.Language);
tw.WriteElementString("ProductVersion", myFileVersionInfo.ProductVersion);
tw.WriteElementString("InternalName", myFileVersionInfo.InternalName);
tw.WriteElementString("Ispatched", myFileVersionInfo.IsPatched.ToString());
tw.WriteEndElement();
}
i = i + 1;
}
}
tw.WriteEndElement();
tw.WriteEndDocument();
tw.Flush();
tw.Close();
DialogResult result;
result = MessageBox.Show("Dlls Information File successfully created at C:\\dll.xml", "DllInformation", MessageBoxButtons.OK, MessageBoxIcon.Information);
TransformXML(XML_File_Path);
if (result == DialogResult.OK)
{
System.Diagnostics.Process.Start(HTML_File_Path);
MessageBox.Show("Happy Testing");
this.Close();
}
}
catch (Exception d)
{
Console.WriteLine("The process failed: {0}", d.ToString());
}
finally
{
Application.Exit();
}
}
public static void TransformXML(string XML_File_Path)
{
XmlUrlResolver resolver = new XmlUrlResolver( );
resolver.Credentials = System.Net.CredentialCache.DefaultCredentials;
XslTransform transform = new XslTransform();
transform.Load(@"c:\\dllHtml.xsl",resolver);
transform.Transform(XML_File_Path, HTML_File_Path, resolver);
}
private void button2_Click(object sender, EventArgs e)
{
FolderBrowserDialog dlg = new FolderBrowserDialog();
dlg.ShowDialog();
if (dlg.ShowDialog() == DialogResult.OK)
{
File_Text.Text = dlg.SelectedPath;
}
}
private void directory_path_TextChanged(object sender, EventArgs e)
{
}
private void button3_Click(object sender, EventArgs e)
{
FolderBrowserDialog dlg = new FolderBrowserDialog();
dlg.ShowDialog();
if (dlg.ShowDialog() == DialogResult.OK)
{
output_folder.Text = dlg.SelectedPath;
}
}
}
}
---------
我需要修改解决方案文件,移除我项目特定的信息,用于某些窗口。我会在一两天内完成,然后上传 C# 解决方案。