vb.netdllversiongetfileversion

VB.net Get DLL File Version


Ive got a project that I have been tasked with, to install some Microsoft KB's, but they want me to check that once the KB has been installed, that it has update the DLL and the only way i can see they differ is by the DLL version.

Is there a way I can get VB.net to check the DLL file version (right click - properties - details - File Version)?

I have found a couple of things on the internet, but I cant get them to work or more likely I do not understand what I need to do to get the correct information.

Any help with this would be great appreciated.


Solution

  • After calling into a DLL, to ensure it's loaded, You can get the info from that DLL (all the stuff you'd see when right clicking on the DLL) using something like this:

    Dim sModule As String
    
    For Each tModule As ProcessModule In Process.GetCurrentProcess().Modules
      sModule = tModule.FileName
      If sModule.ToUpper.Contains(DLLFileName.ToUpper) Then
        Dim myFileVersionInfo As FileVersionInfo = _
               FileVersionInfo.GetVersionInfo(sModule)
        DLLFileAndVersion = sModule & " " & myFileVersionInfo.ProductVersion
      End If
    Next