{"id":71483,"date":"2004-09-08T08:54:00","date_gmt":"2004-09-08T08:54:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2004\/09\/08\/how-can-i-determine-the-version-number-of-an-executable-file\/"},"modified":"2004-09-08T08:54:00","modified_gmt":"2004-09-08T08:54:00","slug":"how-can-i-determine-the-version-number-of-an-executable-file","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/how-can-i-determine-the-version-number-of-an-executable-file\/","title":{"rendered":"How Can I Determine the Version Number of an Executable File?"},"content":{"rendered":"<p><img decoding=\"async\" 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\"><\/p>\n<p>Hey, Scripting Guy! How can I determine the version number of an executable file?<\/p>\n<p>&#8212; TW<\/p>\n<p><img decoding=\"async\" border=\"0\" alt=\"Spacer\" src=\"https:\/\/devblogs.microsoft.com\/scripting\/wp-content\/uploads\/sites\/29\/2019\/05\/spacer.gif\" width=\"5\" height=\"5\"><img decoding=\"async\" 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 decoding=\"async\" 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><\/p>\n<p>Hey, TW. Well, that depends. If the file is located on the local computer, the easiest way is to use the FileSystemObject. Have a burning desire to know which version of Regedit.exe is installed on your computer? All it takes is two lines of code:<\/p>\n<pre class=\"codeSample\">Set objFSO = CreateObject(\"Scripting.FileSystemObject\")\nWscript.Echo objFSO.GetFileVersion(\"c:\\windows\\regedit.exe\")\n<\/pre>\n<p>As you can see, this is about as simple a script as you\u2019ll ever write. In line 1, we create an instance of the FileSystemObject; in line 2, we use the GetFileVersion method to return the version number of C:\\Windows\\Regedit.exe. That\u2019s all there is to it.<\/p>\n<p>OK, we know: some of you are thinking, \u201cSure, that works fine if the file in question is located on the local computer. But what if that file is located on a <i>remote<\/i> computer? After all, the FileSystemObject is designed to work locally, not remotely. What do we do <i>then<\/i>?\u201d<\/p>\n<p>Relax; if the file is located remotely, you can use WMI and the CIM_DataFile class to get back this same information. Here\u2019s a script that reports the version of Regedit,exe installed on the remote computer atl-ws-01:<\/p>\n<pre class=\"codeSample\">strComputer = \"atl-ws-01\"\nSet objWMIService = GetObject _\n    (\"winmgmts:\\\\\" &amp; strComputer &amp; \"\\root\\cimv2\")\nSet colFiles = objWMIService.ExecQuery _\n    (\"SELECT * FROM CIM_DataFile WHERE Name = 'c:\\\\windows\\\\regedit.exe'\")\nFor Each objFile in colFiles\n     Wscript.Echo objFile.Version\nNext\n<\/pre>\n<p>Again, pretty straightforward, with one exception: notice that you have to use two slashes (\\\\) any time you include a path name in a WQL query. As a result, we end up looking for C:\\\\Windows\\\\Regedit.exe rather than C:\\Windows\\Regedit.exe. Other than that it\u2019s a regular old WMI script, the kind you\u2019ve written many times before<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hey, Scripting Guy! How can I determine the version number of an executable file? &#8212; TW Hey, TW. Well, that depends. If the file is located on the local computer, the easiest way is to use the FileSystemObject. Have a burning desire to know which version of Regedit.exe is installed on your computer? All it [&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":[38,3,12,5],"class_list":["post-71483","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-files","tag-scripting-guy","tag-storage","tag-vbscript"],"acf":[],"blog_post_summary":"<p>Hey, Scripting Guy! How can I determine the version number of an executable file? &#8212; TW Hey, TW. Well, that depends. If the file is located on the local computer, the easiest way is to use the FileSystemObject. Have a burning desire to know which version of Regedit.exe is installed on your computer? All it [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/71483","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=71483"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/71483\/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=71483"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=71483"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=71483"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}