using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Windows.Forms;
namespace DllViewer
{
public partial class Form1 : Form
{
private string pName = null;
private string dllName = null;
private Process[] p = null;
private List<string> ls =
new List<string>
();
public Form1()
{
InitializeComponent();
}
private void listAllProcess()
{
ls.Clear();
listBox1.Items.Clear();
p = Process.GetProcesses();
foreach (Process pValue in p)
{
ls.Add(pValue.ProcessName.ToString());
}
ls.Sort();
foreach (string s in ls)
{
listBox1.Items.Add(s);
}
}
private void Form1_Load(object sender, EventArgs e)
{
toolTip1.SetToolTip(button1, "更新");
Properties.Settings ps = Properties.Settings.Default;
this.Size = ps.Size;
this.Location = ps.Location;
listAllProcess();
}
private void button1_Click(object sender, EventArgs e)
{
listAllProcess();
}
private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
ls.Clear();
listBox2.Items.Clear();
pName = listBox1.SelectedItem.ToString();
label3.Text = pName;
p = Process.GetProcessesByName(pName);
try
{
ProcessModuleCollection pmc = p[0].Modules;
foreach (ProcessModule pm in pmc)
{
ls.Add(pm.FileName.ToString());
}
ls.Sort();
foreach (string s in ls)
{
listBox2.Items.Add(s);
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void listBox2_SelectedIndexChanged(object sender, EventArgs e)
{
dllName = listBox2.SelectedItem.ToString();
string dllVersion = null;
string dllFileSize = null;
string dllFileDescription = null;
string pPoductName = null;
string pVersion = null;
string pCopyright = null;
string pCompanyName = null;
p = Process.GetProcessesByName(pName);
ProcessModuleCollection pmc = p[0].Modules;
foreach (ProcessModule pm in pmc)
{
if (String.Compare(pm.FileName.ToString(), dllName) == 0)
{
try
{
dllVersion = pm.FileVersionInfo.FileVersion.ToString().Trim();
dllFileSize = pm.ModuleMemorySize.ToString().Trim();
dllFileDescription = pm.FileVersionInfo.FileDescription.ToString().Trim();
pPoductName = pm.FileVersionInfo.ProductName.ToString().Trim();
pVersion = pm.FileVersionInfo.ProductVersion.ToString().Trim();
pCopyright = pm.FileVersionInfo.LegalCopyright.ToString().Trim();
pCompanyName = pm.FileVersionInfo.CompanyName.ToString().Trim();
}
catch (Exception)
{
;
}
}
}
string msg = String.Format(
"Dll 名稱: {0} \nDll 版本: {1} \nDll 檔案大小: {2} \nDll 檔案描述: {3} \n\n產品名稱: {4} \n產品版本: {5} \n\n公司名稱: {6} \n版權: {7}",
dllName, dllVersion, dllFileSize, dllFileDescription, pPoductName, pVersion, pCompanyName, pCopyright);
MessageBox.Show(msg, "詳細資料", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
Properties.Settings ps = Properties.Settings.Default;
ps.Size = this.Size;
ps.Location = this.Location;
ps.Save();
}
}
}