Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to get DLL version. 1

Status
Not open for further replies.

Targol

Technical User
Sep 13, 2002
908
FR
I've been asked to build a tool to compare DLL from differents directories. For each DLL file found in a specified folder, I need to write it's version, date last modified and size. For the 2 last infos, I managed to get them by the properties of the File object. Does anyone knows how to get the DLL version (shown on the "Version" tab of the "properties" window of a dll file in explorer).

Here is the code I wrote for the moment (Note : this is a full client tool called with a "file:\\..." type Url) :

Code:
<!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0 Transitional//EN&quot;>
<html>
  <head id=&quot;Entete&quot;>
    <title>Récupération des infos DLL</title>
    <LINK rel='stylesheet' type='text/css' href='./InfosDll_fichiers/Style.css'>
    <script language=&quot;vbscript&quot;>
    '*********************************************************
    option explicit
    ' *** VARIABLES GLOBALES ***			
    dim fs, outFile
    dim scanRep, outRep
    dim getVers, getDate, getSize, nbInfos

    ' *** Initialisations GLOBALES ***			
    Set fs = CreateObject(&quot;Scripting.FileSystemObject&quot;)
    '*********************************************************
    function Verif()
    '*********************************************************
      dim oHTM_tmp, nbDll
...
Here are checks on input contents that are OK.
...
Code:
      ' *** Verif des options ***
      nbInfos = 0
      getVers = false
      getDate = false
      getSize = false
      ' Taille
      Set oHTM_tmp = document.getElementById(&quot;ck_Size&quot;)
      if oHTM_tmp.checked Then
        getSize = true
        nbInfos = nbInfos + 1
      End if
      ' Date
      Set oHTM_tmp = document.getElementById(&quot;ck_Date&quot;)
      if oHTM_tmp.checked Then
        getDate = true
        nbInfos = nbInfos + 1
      End if
      ' Version
      Set oHTM_tmp = document.getElementById(&quot;ck_Vers&quot;)
      if oHTM_tmp.checked Then
        getVers = true
        nbInfos = nbInfos + 1
      End if

      if nbInfos = 0 then
        Msgbox &quot;Vous n'avez selectionné aucune information à afficher !!!&quot;
        oHTM_tmp.focus
        exit function
      End if
				
      Set oHTM_tmp = document.getElementById(&quot;MyBody&quot;)
      oHTM_tmp.style.cursor = &quot;wait&quot;
      
      Set outFile = fs.OpenTextFile(outRep & &quot;InfosDLL.txt&quot;, 2, True)
      nbDll = GetAllDlls()
      outFile.close
				
      oHTM_tmp.style.cursor = &quot;auto&quot;

      if Msgbox (nbDll & &quot; ont été scannées, voulez-vous visualiser le résultat ?&quot;, vbYesNo) = vbYes Then
        dim wsh
        Set wsh = CreateObject(&quot;Wscript.Shell&quot;)
	wsh.run &quot;Notepad.exe &quot; & outRep & &quot;InfosDLL.txt&quot;,1,false
        set wsh = nothing
      End if
				
      set fs  = nothing
				
    End Function

    '*********************************************************
    function GetAllDlls()
    '*********************************************************
    dim oRep, oFic, oLstFics, nbDll, nbFics, curFic, curPercent
				
    nbDll = 0
    Set oRep = fs.GetFolder(scanRep)
    Set oLstFics = oRep.Files
    nbFics= oLstFics.count
    curFic = 0
    curPercent = 0
    for each oFic in oLstFics
      if Cint((100 * curFic) / nbFics) <> curPercent Then
        curPercent = Cint((100 * curFic) / nbFics)
	window.status = &quot;Scan du répertoire : &quot; & curPercent & &quot;%&quot;
      End if
      if(lcase(right(oFic.name,3)) = &quot;dll&quot;) Then
        call GetDllInfos(oFic)
        nbDll = nbDll + 1
      End if
      curFic = curFic + 1
    Next
    GetAllDlls = nbDll
  End Function
			
    '*********************************************************
    function GetDllInfos(oFicDll)
    '*********************************************************
      call outFile.Write(oFicDll.name)
      if getVers Then
This is here I need to get the real version instead of the &quot;Hard coded&quot; V1R1L1 :
Code:
        call outFile.Write(chr(9) & &quot;V1R1L1&quot;)
This is here I need to get the real version instead of the &quot;Hard coded&quot; V1R1L1 :
Code:
      End if
      if getDate Then
        call outFile.Write(chr(9) & oFicDll.dateLastModified )
      End if
      if getSize Then
        call outFile.Write(chr(9) & oFicDll.size )
      End if
      call outFile.WriteLine(&quot;&quot;)
    End Function
	
    '*********************************************************
    </script>
  </head>
  <body id=&quot;MyBody&quot; style=&quot;TEXT-ALIGN: center&quot;>
    <H1>Récupération des infos DLL</H1>
    Selectionnez un répertoire et les informations que vous désirez sur les DLL.<BR />
    L'outil va créer un fichier &quot;infosDLL.txt&quot; dans le répertoire de sortie spécifié.<BR />
    Ce fichier contiendra toutes les informations choisies sur toutes les DLL du répertoire scanné.<BR/>
    <BR/>
    <BR/>
    <table width=&quot;90%&quot; border=&quot;0&quot; style=&quot;border-style : outset; border-width : thin;&quot; cellpadding=&quot;5px&quot; cellspacing=&quot;1px&quot; ID=&quot;Table1&quot;>
      <tr>
        <td class=&quot;Titre&quot; colspan=&quot;2&quot; align=&quot;left&quot;>répertoires :</td>
      </tr>
      <tr>
        <td><FONT class=&quot;Lib&quot;>Répertoire à scanner :  </FONT></td>
        <td><input type=&quot;Text&quot; name=&quot;RepToScan&quot; size=&quot;100&quot; ID=&quot;RepToScan&quot;>	</td>
      </tr>
      <tr>
        <td><FONT class=&quot;Lib&quot;>Répertoire de sortie :  </FONT></td>
        <td><input type=&quot;Text&quot; name=&quot;RepOut&quot; size=&quot;100&quot; ID=&quot;RepOut&quot;></td>
      </tr>
    </table>
    <BR/>
    <BR/>
    <table width=&quot;50%&quot; border=&quot;0&quot; style=&quot;border-style : outset;	border-width : thin;&quot; cellpadding=&quot;5px&quot; cellspacing=&quot;1px&quot;>
      <col width=&quot;80%&quot;/>
      <col width=&quot;20%&quot;/>
      <tbody>
        <tr>
          <td class=&quot;Titre&quot; colspan=&quot;2&quot; align=&quot;left&quot;>Options :</td>
        </tr>
        <tr>
          <td class=&quot;Libelle&quot; align=&quot;right&quot;>Afficher la version de DLL :  </td>
          <td align=&quot;left&quot;><input type=&quot;checkbox&quot; name=&quot;ck_Vers&quot; ID=&quot;ck_Vers&quot; checked></td>
        </tr>
        <tr>
          <td class=&quot;Libelle&quot; align=&quot;right&quot;>Afficher la date de dernière modification :  </td>
          <td align=&quot;left&quot;><input type=&quot;checkbox&quot; name=&quot;ck_Date&quot; ID=&quot;ck_Date&quot; checked></td>
        </tr>
        <tr>
          <td class=&quot;Libelle&quot; align=&quot;right&quot;>Afficher la taille du fichier :  </td>
          <td align=&quot;left&quot;><input type=&quot;checkbox&quot; name=&quot;ck_Size&quot; ID=&quot;ck_Size&quot; checked></td>
        </tr>
      </tbody>
    </table>
    <BR/>
    <BR/>
    <input type=&quot;button&quot; style=&quot;width : 150px;&quot; value=&quot;Valider&quot; onClick=&quot;Verif()&quot;/>
  </body>
</html>
Water is not bad as long as it stays out human body ;-)
 
For 32-bit DLLs you can use the FSO GetFileVersion() method. It will fail on 9x systems if you feed it a 16-bit Win 3.1 DLL and most DOS DLLs though.

This can be hard to trap, because it throws the same exception as when your file spec is invalid. If you know there file is there, for example because you found it doing a directory scan, you can use code like:
Code:
Dim FSO, fspec, ver

Set FSO = CreateObject(&quot;Scripting.FileSystemObject&quot;)
fspec = InputBox(&quot;File?&quot;)
On Error Resume Next
ver = FSO.GetFileVersion(fspec)
If Err.Number = &H800700a1 Then
  ver = &quot;Not a 32-bit DLL&quot;
  Err.Clear
End If
On Error GoTo 0
MsgBox ver
 
Thanx dilettante, you did best than MS premier support that told me that that couldn't be done without a COM object. I give you a star for that. Unfortunatelly, the version I need is not this one. The DLLs have been created with an old french program called NS-DK and the version I need is a string of this type &quot;VnRnLn&quot; stored elsewhere (but WHERE [morning]???) in the file. Water is not bad as long as it stays out human body ;-)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top