Chris (mc_funkymcmeep) wrote in ncommunity,
Chris
mc_funkymcmeep
ncommunity

DLL Management Code?

I've been asked to find some sort of program, or better yet some code (and even better in Visual Basic of some variety) that will (I think) check the DLLs and their versions that are being loaded against what the program is expecting, or something similar (sorry, it wasn't made very clear.)

Any suggestions? Thanks
Subscribe
  • Post a new comment

    Error

    default userpic

    Your IP address will be recorded 

    When you submit the form an invisible reCAPTCHA check will be performed.
    You must follow the Privacy Policy and Google Terms of use.
  • 5 comments
Well, you should be able to find out which DLLs it loads by doing something like this (C#):

ProcessStartInfo psi = new ProcessStartInfo();
// ... set up psi to point to the right EXE and so on
Process p = new Process();
p.StartInfo = pi;
p.Start();

foreach(ProcessModule mod in p.Modules){
 Console.WriteLine("Module "+mod.FileName+" is version "+mod.FileVersionInfo);
}


If the target is a .Net executable then you should be able to use Reflection to read the manifest on the assembly and find out what versions it was expecting. Otherwise you might want to have a text config file that tells you what versions it's expecting. To wit,

Assembly a = Assembly.LoadFrom("wherever.exe");
foreach(AssemblyName refd in a.GetReferencedAssemblies())
 Console.WriteLine("Expecting "+refd.FullName+" to be version "+refd.Version);


Hope that helps!

Deleted comment

Um ... it should come with the Framework! Have you got version 1.1?

Yeah, sorry, I should have mentioned where things are. Process and ProcessStartInfo are in the System.Diagnostics namespace (System.dll); Assembly and friends are in System.Reflection (in Mscorlib).
Strike my previous comments, I got it working.
Thanks!
I suspect this can easily be ported to VB.NET as they're all suppose to be compatible, but is there anyway to get this code to work in VB6/VBA?

The project I'm on is currently using VB6/VBA, but we're ultimately auditing this stuff so it can be ported to .NET.
No idea, mate, sorry. I have zero experience of VB (hence why I posted in C#). I guess there's Windows API calls you can make to find the version of a DLL, but as there's no manifest in a non-.Net world you couldn't check what you were expecting.
Thanks a lot, this code is great!

Now only if I can find something for VB6 somehow.

:)