{"id":67273,"date":"2006-05-22T19:50:00","date_gmt":"2006-05-22T19:50:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2006\/05\/22\/how-can-i-get-a-list-of-all-the-dll-files-in-a-folder-along-with-their-version-numbers\/"},"modified":"2006-05-22T19:50:00","modified_gmt":"2006-05-22T19:50:00","slug":"how-can-i-get-a-list-of-all-the-dll-files-in-a-folder-along-with-their-version-numbers","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/how-can-i-get-a-list-of-all-the-dll-files-in-a-folder-along-with-their-version-numbers\/","title":{"rendered":"How Can I Get a List of All the .dll Files in a Folder, Along with Their Version Numbers?"},"content":{"rendered":"<p><IMG class=\"nearGraphic\" title=\"Hey, Scripting Guy! Question\" border=\"0\" alt=\"Hey, Scripting Guy! Question\" align=\"left\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/q-for-powertip.jpg\" width=\"34\" height=\"34\"> \n<P>Hey, Scripting Guy! How can I get a list of all the .dll files in a folder, along with their version numbers?<BR><BR>&#8212; DD<\/P><IMG border=\"0\" alt=\"Spacer\" src=\"https:\/\/devblogs.microsoft.com\/scripting\/wp-content\/uploads\/sites\/29\/2019\/05\/spacer.gif\" width=\"5\" height=\"5\"><IMG class=\"nearGraphic\" title=\"Hey, Scripting Guy! Answer\" border=\"0\" alt=\"Hey, Scripting Guy! Answer\" align=\"left\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/a-for-powertip.jpg\" width=\"34\" height=\"34\"><A href=\"http:\/\/go.microsoft.com\/fwlink\/?linkid=68779&amp;clcid=0x409\"><IMG class=\"farGraphic\" title=\"Script Center\" border=\"0\" alt=\"Script Center\" align=\"right\" src=\"http:\/\/img.microsoft.com\/library\/media\/1033\/technet\/images\/scriptcenter\/ad.jpg\" width=\"120\" height=\"288\"><\/A> \n<P>Hey, DD. You know, when we sit down to write this column we usually try to start off with an amusing and at least semi-relevant anecdote. In this case, that would mean a cute story about file versions. Unfortunately, none of the Scripting Guys could come up with an amusing anecdote about file versions; instead, the only things we could recall were nightmare scenarios involving mismatched, out-of-date, or incorrect .dll files. Talk about dredging up unpleasant memories: we didn\u2019t think poor Dean would <I>ever<\/I> stop crying!<\/P>\n<P>In other words, it\u2019s safe to say that having a list of all the .dll files in a folder, along with the version number of each of those files, would be a pretty handy little thing to have. And what better way to retrieve that data than by using a script:<\/P><PRE class=\"codeSample\">strComputer = &#8220;.&#8221;<\/p>\n<p>Set objWMIService = GetObject(&#8220;winmgmts:\\\\&#8221; &amp; strComputer &amp; &#8220;\\root\\cimv2&#8221;)<\/p>\n<p>Set colFileList = objWMIService.ExecQuery _\n    (&#8220;ASSOCIATORS OF {Win32_Directory.Name=&#8217;C:\\Windows\\System32&#8242;} Where &#8221; _\n        &amp; &#8220;ResultClass = CIM_DataFile&#8221;)<\/p>\n<p>For Each objFile In colFileList\n    If objFile.Extension = &#8220;dll&#8221; Then\n        Wscript.Echo objFile.Name &amp; &#8221; &#8212; &#8221; &amp; objFile.Version\n    End If\nNext\n<\/PRE>\n<P>As you can see, we chose to tackle this problem by using a WMI script. Admittedly, we could have achieved the same results by using the FileSystemObject. We opted to go with WMI for one simple reason: that enables us to run this script against remote computers. (By contrast, the FileSystemObject pretty much limits us to working with the local computer.) Need to get file information off a remote computer named atl-fs-01? No problem; all you have to do is take the preceding script and change line 1 to look like this:<\/P><PRE class=\"codeSample\">strComputer = &#8220;atl-fs-01&#8221;\n<\/PRE>\n<P>And, yes, that\u2019s <I>exactly<\/I> why we like WMI so much.<\/P>\n<P>The script itself starts off by connecting to the WMI service on the local computer. We then run into this crazy-looking line of code:<\/P><PRE class=\"codeSample\">Set colFileList = objWMIService.ExecQuery _\n    (&#8220;ASSOCIATORS OF {Win32_Directory.Name=&#8217;C:\\Windows\\System32&#8242;} Where &#8221; _\n        &amp; &#8220;ResultClass = CIM_DataFile&#8221;)\n<\/PRE>\n<P>It\u2019s not pretty, but this is how you retrieve a collection of all the files in a specified folder (in this case, C:\\Windows\\System32). Basically what we\u2019re saying here is this: \u201cBring me back all the CIM_DataFile objects associated with the directory named C:\\Windows\\System32.\u201d Because CIM_Datafile is the WMI class that represents files, this query &#8211; crazy as it might look &#8211; simply brings back a collection of all the files found in C:\\Windows\\System32. What if you wanted a collection of all the files found in D:\\Test? In that case you\u2019d modify your query to look like this:<\/P><PRE class=\"codeSample\">Set colFileList = objWMIService.ExecQuery _\n    (&#8220;ASSOCIATORS OF {Win32_Directory.Name=&#8217;D:\\Test&#8217;} Where &#8221; _\n        &amp; &#8220;ResultClass = CIM_DataFile&#8221;)\n<\/PRE>\n<P>If you want to know more about Associators Of queries then check out the <A href=\"http:\/\/msdn.microsoft.com\/library\/en-us\/wmisdk\/wmi\/associators_of_statement.asp\" target=\"_blank\"><B>WMI SDK<\/B><\/A> on MSDN. Alternatively, don\u2019t worry too much about the nitty-gritty details; just remember that all you have to do is set <B>Win32_Directory.Name<\/B> to the name of the folder you want to work with.<\/P>\n<P>From here on it\u2019s a piece of cake. Once we have our collection we set up a For Each loop to walk us through each item (each file) in the collection. Inside that loop we use this line of code to check the value of the <B>Extension<\/B> property:<\/P><PRE class=\"codeSample\">If objFile.Extension = &#8220;dll&#8221; Then\n<\/PRE>\n<P>If Extension is equal to dll (note that this is just the three letters <B>dll<\/B>, without a dot; don\u2019t include the dot when specifying the file extension in WMI) we then use this line of code to echo back the <B>Name<\/B> and <B>Version<\/B>:<\/P><PRE class=\"codeSample\">Wscript.Echo objFile.Name &amp; &#8221; &#8212; &#8221; &amp; objFile.Version\n<\/PRE>\n<P>And what if the file extension <I>isn\u2019t<\/I> equal to dll? No problem; in that case we just loop around and repeat the process with the next item in the collection.<\/P>\n<P>When all is said and done we\u2019ll get back information similar to this:<\/P><PRE class=\"codeSample\">C:\\Scripts&gt;cscript dlls.vbs\nMicrosoft (R) Windows Script Host Version 5.6\nCopyright (C) Microsoft Corporation 1996-2001. All rights reserved.<\/p>\n<p>c:\\windows\\system32\\6to4svc.dll &#8212; 5.1.2600.2180 (xpsp_sp2_rtm.040803-2158)\nc:\\windows\\system32\\aaaamon.dll &#8212; 5.1.2600.0 (xpclient.010817-1148)\nc:\\windows\\system32\\acctres.dll &#8212; 6.00.2600.0000 (xpclient.010817-1148)\nc:\\windows\\system32\\acledit.dll &#8212; 5.1.2600.0 (xpclient.010817-1148)\nc:\\windows\\system32\\aclui.dll &#8212; 5.1.2600.2180 (xpsp_sp2_rtm.040803-2158)\nc:\\windows\\system32\\activeds.dll &#8212; 5.1.2600.2180 (xpsp_sp2_rtm.040803-2158)\n<\/PRE>\n<P>Believe it or not, that\u2019s all it takes. (Boy, could we have used a script like this a few years ago!) Now, we should point out that this script &#8211; as requested &#8211; only retrieves information about the .dll files found in a single folder; the script does not check for .dll files in any subfolders of that folder. Could we modify the code and get the script to search all the subfolders of the target folder? Sure; as a starting point, take a look at this <A href=\"http:\/\/null\/technet\/scriptcenter\/resources\/qanda\/feb05\/hey0218.mspx\"><B>Hey, Scripting Guy!<\/B><\/A> column, which shows you how to retrieve a list of all the files in a folder and its subfolders. All you need to do is take that script and look for the line of code that echoes back the file name:<\/P><PRE class=\"codeSample\">Wscript.Echo objFile.Name\n<\/PRE>\n<P>Modify that line to echo back the file name <I>and<\/I> the file version, and you\u2019ll be in business:<\/P><PRE class=\"codeSample\">Wscript.Echo objFile.Name &amp; &#8221; &#8212; &#8221; &amp; objFile.Version\n<\/PRE>\n<P>Got all that? Great. As for the Scripting Guys, we\u2019re off to buy Dean an ice cream cone; we\u2019re hoping that will cheer him up a bit. Poor little guy \u2026.<\/P><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hey, Scripting Guy! How can I get a list of all the .dll files in a folder, along with their version numbers?&#8212; DD Hey, DD. You know, when we sit down to write this column we usually try to start off with an amusing and at least semi-relevant anecdote. In this case, that would mean [&hellip;]<\/p>\n","protected":false},"author":595,"featured_media":87096,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[715,38,3,12,5],"class_list":["post-67273","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-associators-of","tag-files","tag-scripting-guy","tag-storage","tag-vbscript"],"acf":[],"blog_post_summary":"<p>Hey, Scripting Guy! How can I get a list of all the .dll files in a folder, along with their version numbers?&#8212; DD Hey, DD. You know, when we sit down to write this column we usually try to start off with an amusing and at least semi-relevant anecdote. In this case, that would mean [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/67273","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/users\/595"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/comments?post=67273"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/67273\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media\/87096"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media?parent=67273"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=67273"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=67273"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}