日期:2014-05-20 浏览次数:21052 次
using System.Reflection;
public static class Pub
{
public static Assembly[] GetGAC()
{
Assebmly[] gac;
// TODO ...
return gac;
}
}
// 实例一个Process类,启动一个独立进程
Process p = new Process();
// 设定程序名
p.StartInfo.FileName = "cmd.exe";
// 关闭Shell的使用
p.StartInfo.UseShellExecute = false;
// 重定向标准输入
p.StartInfo.RedirectStandardInput = true;
// 重定向标准输出
p.StartInfo.RedirectStandardOutput = true;
//重定向错误输出
p.StartInfo.RedirectStandardError = true;
// 设置不显示窗口
p.StartInfo.CreateNoWindow = true;
// 启动进程
string pingrst;
p.Start();
p.StandardInput.WriteLine("ping -n 1 " + strIp);
p.StandardInput.WriteLine("exit");
// 从输出流获取命令执行结果
string strRst = p.StandardOutput.ReadToEnd();
------解决方案--------------------
模拟cmd命令,先获取GAC里dll文件,再通过反射路径下的DLL获取相关信息
cd c:\windows\accembly\GAC_MSIL
xcopy *.* c:\temp\ /e
------解决方案--------------------
试试吧,就是效率不高:
public static Assembly[] GetGAC()
{
List<Assembly> list = new List<Assembly>();
foreach (string s in Directory.GetFiles(@"C:\Windows\assembly", "*.*", SearchOption.AllDirectories))
{
try
{
Assembly ass = Assembly.LoadFrom(s);
if (ass != null)
list.Add(ass);
}
catch
{
continue;
}
}
return list.ToArray();
}
------解决方案--------------------
msdn
Knowledge Base
id=317540
DOC: Global Assembly Cache (GAC) APIs Are Not Documented in the .NET Framework Software Development Kit (SDK) Documentation