Determine Loaded Assemblies

2019-04-24 14:34发布

How can I determine all of the assemblies that my .NET desktop application has loaded? I'd like to put them in the about box so I can query customers over the phone to determine what version of XYZ they have on their PC.

It would be nice to see both managed and unmanaged assemblies. I realize the list will get long but I plan to slap an incremental search on it.

5条回答
成全新的幸福
2楼-- · 2019-04-24 15:05

Looks like AppDomain.CurrentDomain.GetAssemblies(); will do the trick :)

查看更多
家丑人穷心不美
3楼-- · 2019-04-24 15:06

Either that, or System.Reflection.Assembly.GetLoadedModules().

Note that AppDomain.GetAssemblies will only iterate assemblies in the current AppDomain. It's possible for an application to have more than one AppDomain, so that may or may not do what you want.

查看更多
Root(大扎)
4楼-- · 2019-04-24 15:19

PowerShell Version:

[System.AppDomain]::CurrentDomain.GetAssemblies()
查看更多
虎瘦雄心在
5楼-- · 2019-04-24 15:22
using System;
using System.Reflection;
using System.Windows.Forms;

public class MyAppDomain
{
  public static void Main(string[] args)
  {
    AppDomain ad = AppDomain.CurrentDomain;
    Assembly[] loadedAssemblies = ad.GetAssemblies();

    Console.WriteLine("Here are the assemblies loaded in this appdomain\n");
    foreach(Assembly a in loadedAssemblies)
    {
      Console.WriteLine(a.FullName);
    }
  }
}
查看更多
兄弟一词,经得起流年.
6楼-- · 2019-04-24 15:24

For all DLLs including unmanaged, you could pinvoke EnumProcessModules to get the module handles and then use GetModuleFileName for each handle to get the name.

See http://pinvoke.net/default.aspx/psapi.EnumProcessModules and http://msdn.microsoft.com/en-us/library/ms683197(VS.85).aspx (pinvoke.net does not have the signature for this but it's easy to figure out).

For 64 bit you need to use EnumProcessModulesEx

查看更多
登录 后发表回答