{"id":4520,"date":"2021-11-10T14:12:23","date_gmt":"2021-11-10T14:12:23","guid":{"rendered":"https:\/\/lgildv5i97.onrocket.site\/answers\/?post_type=question&#038;p=4520"},"modified":"2021-11-10T14:12:38","modified_gmt":"2021-11-10T14:12:38","slug":"batch-how-to-get-file-version-using-wmic-of-any-application-exe-dll","status":"publish","type":"question","link":"https:\/\/computing.net\/answers\/batch-how-to-get-file-version-using-wmic-of-any-application-exedll\/993.html","title":{"rendered":"[Batch] How to get file version using WMIC of any application (*.exe,*.dll)"},"content":{"rendered":"<p>This batch script can get file version of any application\u00a0<span class=\"mycode_b\">(*.exe ;*.dll)<\/span>\u00a0inside a directory (in my example i\u00a0<span class=\"mycode_b\">set &#8220;RootFolder=%ProgramData%&#8221;<\/span>); so you can change it as you want like (<span class=\"mycode_b\">set &#8220;RootFolder=%AppData%&#8221;<\/span>) and so on &#8230;<br \/>\nJust Change this Variable in your case and the script will do the rest.<\/p>\n<p>For any update just check this link : https:\/\/pastebin.com\/uWscW7rU<\/p>\n<p><b>GetFileVersion.bat<\/b><i><\/i><\/p>\n<p>@echo off<br \/>\nMode 75,3 &amp; color 9E<br \/>\nTitle Get File Version of any Application from file list using WMIC by Hackoo<br \/>\n::******************************************************************************<br \/>\nREM Just Change this Variable in your case and the script will do the rest (-_\u00b0)<br \/>\nSet &#8220;RootFolder=%ProgramData%&#8221;<br \/>\n::******************************************************************************<br \/>\n:Main<br \/>\n@for %%a in (&#8220;%RootFolder%&#8221;) do set &#8220;FolderName=%%~na&#8221;<br \/>\nSet &#8220;File_Version_List=%~dp0%FolderName%_File_Version_List.txt&#8221;<br \/>\nSet &#8220;ErrorFile=%~dp0%FolderName%_Error.txt<br \/>\nSet Extensions=&#8221;*.exe&#8221; &#8220;*.dll&#8221;<br \/>\nIf exist &#8220;%ErrorFile%&#8221; Del &#8220;%ErrorFile%&#8221;<br \/>\nIf exist &#8220;%File_Version_List%&#8221; Del &#8220;%File_Version_List%&#8221;<br \/>\necho(<br \/>\necho\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Please wait a while &#8230; Process to get file version &#8230;<br \/>\nset &#8220;BuildLineWith=call :BuildLine &#8221;<br \/>\nsetlocal enabledelayedexpansion<br \/>\nCD \/D &#8220;%RootFolder%&#8221;<br \/>\n@for \/f &#8220;delims=&#8221; %%F in (&#8216;Dir \/b \/s %Extensions%&#8217;) do (<br \/>\nset &#8220;Version=&#8221;<br \/>\nCall :Get_AppName &#8220;%%F&#8221; AppName<br \/>\nCall :Add_backSlash &#8220;%%F&#8221;<br \/>\nCall :GetVersion !Application! Version<br \/>\nCall :Remove_backSlash !Application!<br \/>\nIf defined Version (<br \/>\n(<br \/>\necho !Application!<br \/>\necho !AppName! ==^&gt; !Version!<br \/>\n%BuildLineWith%*<br \/>\n)&gt;&gt; &#8220;%File_Version_List%&#8221;<br \/>\n) else (<br \/>\n(<br \/>\necho Version is not defined in !Application!<br \/>\n%BuildLineWith%#<br \/>\n)&gt;&gt; &#8220;%ErrorFile%&#8221;<br \/>\n)<br \/>\n)<br \/>\nIf Exist &#8220;%ErrorFile%&#8221; Start &#8220;&#8221; &#8220;%ErrorFile%&#8221;<br \/>\nIf Exist &#8220;%File_Version_List%&#8221; Start &#8220;&#8221; \/MAX &#8220;%File_Version_List%&#8221; &amp; Exit<br \/>\n::*******************************************************************<br \/>\n:GetVersion<i><\/i><i><br \/>\nRem The argument %~1 represent the full path of the application<br \/>\nRem without the double quotes<br \/>\nRem The argument %2 represent the variable to be set (in our case %2=Version)<br \/>\nFOR \/F &#8220;tokens=2 delims==&#8221; %%I IN (<br \/>\n&#8216;wmic datafile where &#8220;name=&#8217;%~1&#8242;&#8221; get version \/format:Textvaluelist 2^&gt;^nul&#8217;<br \/>\n) DO FOR \/F &#8220;delims=&#8221; %%A IN (&#8220;%%I&#8221;) DO SET &#8220;%2=%%A&#8221;<br \/>\nExit \/b<br \/>\n::*******************************************************************<br \/>\n:Add_backSlash<\/i><i><br \/>\nRem Subroutine to replace the simple &#8220;\\&#8221; by a double &#8220;\\\\&#8221; into a String<br \/>\nSet &#8220;Application=%1&#8221;<br \/>\nSet &#8220;String=\\&#8221;<br \/>\nSet &#8220;NewString=\\\\&#8221;<br \/>\nCall Set &#8220;Application=%%Application:%String%=%NewString%%%&#8221;<br \/>\nExit \/b<br \/>\n::*******************************************************************<br \/>\n:Remove_backSlash<\/i><i><br \/>\nRem Subroutine to replace the double &#8220;\\\\&#8221; by a simple &#8220;\\&#8221; into a String<br \/>\nSet &#8220;Application=%1&#8221;<br \/>\nSet &#8220;String=\\\\&#8221;<br \/>\nSet &#8220;NewString=\\&#8221;<br \/>\nCall Set &#8220;Application=%%Application:%String%=%NewString%%%&#8221;<br \/>\nExit \/b<br \/>\n::*******************************************************************<br \/>\n:Get_AppName<\/i><i><\/i><i><br \/>\nRem %1 = FullPath<br \/>\nRem %2 = AppName<br \/>\nfor %%i in (%1) do set &#8220;%2=%%~nxi&#8221;<br \/>\nexit \/b<br \/>\n::*******************************************************************<br \/>\n:BuildLine<br \/>\nREM Thanks to ImDeepWithWindows for this nice trick of BuildLine<br \/>\nset &#8220;LineChar=%1&#8221;<br \/>\nif &#8220;%LineChar%&#8221;==&#8221;&#8221; set &#8220;LineChar=_&#8221;<br \/>\nfor \/f &#8220;tokens=2 skip=4&#8221; %%A in (&#8216;mode con: \/status&#8217;) do set &#8220;WindowColumns=%%A&#8221; &amp; goto :GotColumnCount<br \/>\n:GotColumnCount<br \/>\nset &#8220;CharLine=&#8221;<br \/>\nsetlocal EnableDelayedExpansion<br \/>\nfor \/L %%A in (1,1,%WindowColumns%) do set &#8220;CharLine=!CharLine!!LineChar:~0,1!&#8221;<br \/>\nsetlocal DisableDelayedExpansion<br \/>\nendlocal<br \/>\necho %CharLine%<br \/>\ngoto :eof<br \/>\n::*******************************************************************<\/i><\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"inline_featured_image":false,"iawp_total_views":20},"question-category":[55],"question_tags":[],"class_list":["post-4520","question","type-question","status-publish","hentry","question-category-programming"],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/computing.net\/answers\/wp-json\/wp\/v2\/question\/4520","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/computing.net\/answers\/wp-json\/wp\/v2\/question"}],"about":[{"href":"https:\/\/computing.net\/answers\/wp-json\/wp\/v2\/types\/question"}],"author":[{"embeddable":true,"href":"https:\/\/computing.net\/answers\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/computing.net\/answers\/wp-json\/wp\/v2\/comments?post=4520"}],"wp:attachment":[{"href":"https:\/\/computing.net\/answers\/wp-json\/wp\/v2\/media?parent=4520"}],"wp:term":[{"taxonomy":"question-category","embeddable":true,"href":"https:\/\/computing.net\/answers\/wp-json\/wp\/v2\/question-category?post=4520"},{"taxonomy":"question_tags","embeddable":true,"href":"https:\/\/computing.net\/answers\/wp-json\/wp\/v2\/question_tags?post=4520"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}