{"id":8452,"date":"2019-04-02T14:58:15","date_gmt":"2019-04-02T09:28:15","guid":{"rendered":"http:\/\/198.58.113.91\/blog\/?p=8452"},"modified":"2023-08-02T20:30:12","modified_gmt":"2023-08-02T15:00:12","slug":"bat-files-do-not-run-when-double-clicked-fix-association","status":"publish","type":"post","link":"https:\/\/www.winhelponline.com\/blog\/bat-files-do-not-run-when-double-clicked-fix-association\/","title":{"rendered":"[Fix] Windows Batch Files (.bat) do not run when double-clicked"},"content":{"rendered":"<p>When you double-click a Windows batch file (<code>.bat<\/code>) or a <code>.cmd<\/code> file, one of the following symptoms may happen:<\/p>\n<ol>\n<li>The error <em><strong>&#8220;Windows cannot find &#8216;filename.bat&#8217;. Make sure you typed the name correctly, and then try again.&#8221;<\/strong><\/em> occurs when you run a .bat or a .cmd file.<\/li>\n<li>The batch file opens a Command Prompt window, but its commands don&#8217;t execute.<\/li>\n<li>Notepad or any other text editor opens the batch file.<\/li>\n<\/ol>\n<h2>Cause<\/h2>\n<p>The user may have inadvertently associated <code>.bat<\/code> files with a text editor, or associated .bat files with <code>cmd.exe<\/code>, or tampered with the settings in the registry. Once you set a file association for <code>.bat<\/code> files using the Open with dialog or default programs, there is no way to revert to the default setting using the user interface. The only way to fix it is by changing the settings in the registry.<\/p>\n<p>The error Windows cannot find &#8216;filename.cmd&#8217; or &#8216;filename.bat&#8217; occurs if the COMSPEC environment variable is incorrect.<\/p>\n<h2>Resolution<\/h2>\n<p>Windows Batch file (<code>.bat<\/code>) and .cmd files are special file types that you can run or automate commands. The Command Prompt reads and interprets the batch\/cmd file and runs each command specified in the file.<\/p>\n<h3>Step 1: Fix the COMPSPEC variable<\/h3>\n<p>If you receive the error &#8220;Windows cannot find &#8216;filename&#8221; when running a .bat or a .cmd file, fix the COMSPEC variable.<\/p>\n<p>Open an <a href=\"https:\/\/www.winhelponline.com\/blog\/open-elevated-command-prompt-windows\/\">admin Command Prompt<\/a> window and run:<\/p>\n<pre>setx ComSpec %SystemRoot%\\system32\\cmd.exe \/m<\/pre>\n<p>Press Enter.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-42091\" src=\"https:\/\/www.winhelponline.com\/blog\/wp-content\/uploads\/2019\/04\/comspec-fix-setx.png\" alt=\"comspec setx\" width=\"599\" height=\"142\" \/><\/p>\n<p>You should see the message <em><strong>SUCCESS: Specified value was saved<\/strong><\/em> in the output.<\/p>\n<p>Exit the Command Prompt window.<\/p>\n<p>The above step should fix the error &#8220;Windows cannot find &#8216;filename&#8217; when running .bat or .cmd files.<\/p>\n<h3>Step 2: Fix the .BAT file association<\/h3>\n<p>To fix symptoms 2 &amp; 3 explained earlier, the .bat file association must be repaired.<\/p>\n<h4>Method 1: Use .BAT\/.cmd file association registry fix<\/h4>\n<ol>\n<li>Download the <a href=\"https:\/\/www.winhelponline.com\/fileasso\/bat_fix_w10.zip\">.bat fix<\/a> or <a href=\"https:\/\/www.winhelponline.com\/fileasso\/cmd_fix_w10.zip\">.cmd fix<\/a> for <strong>Windows 10\/11 <\/strong>from the <a href=\"https:\/\/www.winhelponline.com\/blog\/file-association-fixes-windows-10\/\">file association fixes<\/a> page.<\/li>\n<li>Unzip the archive and double-click the enclosed registry file.<\/li>\n<li>Click <strong>Yes<\/strong> when you&#8217;re asked for confirmation to continue.<\/li>\n<li>Click OK.<\/li>\n<\/ol>\n<hr \/>\n<h4>Method 2: Fix the .BAT file association manually<\/h4>\n<ol>\n<li>Start the Registry Editor (<code>regedit.exe<\/code>)<\/li>\n<li>Go to the following key:\n<pre>HKEY_CLASSES_ROOT\\.bat<\/pre>\n<\/li>\n<li>Set the <code>(default)<\/code> value data to <code>batfile<\/code><\/li>\n<li>Go to the following key:\n<pre>HKEY_CLASSES_ROOT\\batfile\\shell<\/pre>\n<\/li>\n<li>In the right-pane, make sure that the <code>(default)<\/code> value data is not set. It should read as <code>value not set<\/code>. In case you see some other text there, then right-click the <code>(default)<\/code> value and choose <code>Delete<\/code>.<\/li>\n<li>Then, proceed to the following key:\n<pre>HKEY_CLASSES_ROOT\\batfile\\shell\\open\\command<\/pre>\n<\/li>\n<li>Double-click <code>(default)<\/code> and set its value data to:\n<pre>\"%1\" %*<\/pre>\n<\/li>\n<li>Go to the following branch:\n<pre>HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\FileExts\\.bat<\/pre>\n<p>The values present under one of its subkeys (<code>OpenWithList<\/code>, <code>OpenWithProgids<\/code> and <code>UserChoice<\/code>) may be causing the problem.<\/li>\n<li>Right-click on the <code>.bat<\/code> key, and choose <code>Delete<\/code>. Click <code>Yes<\/code> when prompted for confirmation. <strong>Don&#8217;t worry!<\/strong> This registry key and its three subkeys are trivial, and they&#8217;re only required if you want to override the <code>.bat<\/code> file association defaults.<\/li>\n<li>Exit the Registry Editor.<\/li>\n<\/ol>\n<div class=\"qt\">\n<h4>Automate the above steps using REG file<\/h4>\n<p>To automate the steps listed in Method 2 using a <a href=\"https:\/\/www.winhelponline.com\/blog\/how-to-use-reg-files-registration-entries-windows\/\">REG file<\/a>, do the following..<\/p>\n<ol>\n<li>Open Notepad.<\/li>\n<li>Copy the following lines and paste them into Notepad.\n<pre>Windows Registry Editor Version 5.00\r\n\r\n[HKEY_LOCAL_MACHINE\\SOFTWARE\\Classes\\.bat]\r\n@=\"batfile\"\r\n\r\n[HKEY_LOCAL_MACHINE\\SOFTWARE\\Classes\\batfile\\shell]\r\n@=-\r\n\r\n[HKEY_LOCAL_MACHINE\\SOFTWARE\\Classes\\batfile\\shell\\open\\command]\r\n@=\"\\\"%1\\\" %*\"\r\n\r\n[-HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\FileExts\\.bat]\r\n\r\n<\/pre>\n<\/li>\n<li>Save the file with any name having the <code>.reg<\/code> extension, say <code>fix_bat.reg<\/code><\/li>\n<li>Double-click <code>fix_bat.reg<\/code> to apply the configuration in the registry. Click Yes when prompted for confirmation.<\/li>\n<\/ol>\n<\/div>\n<p>That&#8217;s it! You&#8217;ve now fixed the batch file association settings. Batch files should now execute correctly when double-clicked.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>When you double-click a Windows batch file (.bat) or a .cmd file, one of the following symptoms may happen: The error &#8220;Windows cannot find &#8216;filename.bat&#8217;. Make sure you typed the name correctly, and then try again.&#8221; occurs when you run a .bat or a .cmd file. The batch file opens a Command Prompt window, but &#8230; <a title=\"[Fix] Windows Batch Files (.bat) do not run when double-clicked\" class=\"read-more\" href=\"https:\/\/www.winhelponline.com\/blog\/bat-files-do-not-run-when-double-clicked-fix-association\/\" aria-label=\"Read more about [Fix] Windows Batch Files (.bat) do not run when double-clicked\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[7],"tags":[191,209,441],"class_list":["post-8452","post","type-post","status-publish","format-standard","hentry","category-windows","tag-error-messages","tag-file-association","tag-registry"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack-related-posts":[{"id":153,"url":"https:\/\/www.winhelponline.com\/blog\/change-the-default-editor-for-bat-files\/","url_meta":{"origin":8452,"position":0},"title":"Change the Default Editor for Batch files in Windows","author":"Ramesh","date":"April 4, 2008","format":false,"excerpt":"When you right-click on a Windows batch file (.bat) file and click Edit, Notepad opens the file by default. If you have a Notepad replacement software installed in your system, you can set it as the default editor for Windows batch files. Change the Default Editor for Batch Files Launch\u2026","rel":"","context":"In &quot;Windows&quot;","block_context":{"text":"Windows","link":"https:\/\/www.winhelponline.com\/blog\/category\/microsoft\/windows\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/www.winhelponline.com\/blog\/wp-content\/uploads\/bat-icon.gif?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":425,"url":"https:\/\/www.winhelponline.com\/blog\/run-bat-files-invisibly-without-displaying-command-prompt\/","url_meta":{"origin":8452,"position":1},"title":"How to run .BAT files invisibly, without displaying the Command Prompt window","author":"Ramesh","date":"August 5, 2008","format":false,"excerpt":"Batch files (.BAT) and Windows NT Command Script (.CMD) files run in console window when double-clicked. This means that the Command Prompt window will be visible until the .BAT or .CMD file execution is complete. To make .BAT or .CMD file execution less intrusive, you can configure it to run\u2026","rel":"","context":"In &quot;Utilities&quot;","block_context":{"text":"Utilities","link":"https:\/\/www.winhelponline.com\/blog\/category\/utilities\/"},"img":{"alt_text":"run batch file hidden - nircmd exec","src":"https:\/\/i0.wp.com\/www.winhelponline.com\/blog\/wp-content\/uploads\/2008\/08\/nircmd-batch-file-hidden.png?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":3968,"url":"https:\/\/www.winhelponline.com\/blog\/automatically-elevate-batch-file-run-administrator\/","url_meta":{"origin":8452,"position":2},"title":"How to Automatically Elevate a Batch file to Run it as Administrator?","author":"Ramesh","date":"September 2, 2016","format":false,"excerpt":"To elevate batch files manually, you would right-click on it and choose Run as Administrator. Here is a way to automatically elevate a batch file that requires elevated privileges to run correctly. This is equivalent to choosing \"Run as Administrator\" by right-clicking a batch file. In either case, the UAC\u2026","rel":"","context":"In &quot;Windows&quot;","block_context":{"text":"Windows","link":"https:\/\/www.winhelponline.com\/blog\/category\/microsoft\/windows\/"},"img":{"alt_text":"bat file default runas elevated","src":"https:\/\/i0.wp.com\/www.winhelponline.com\/blog\/wp-content\/uploads\/2016\/09\/bat-elevated-2.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.winhelponline.com\/blog\/wp-content\/uploads\/2016\/09\/bat-elevated-2.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/www.winhelponline.com\/blog\/wp-content\/uploads\/2016\/09\/bat-elevated-2.png?resize=525%2C300&ssl=1 1.5x"},"classes":[]},{"id":1282,"url":"https:\/\/www.winhelponline.com\/blog\/file-asso-fixes-for-windows-8\/","url_meta":{"origin":8452,"position":3},"title":"File Association Fixes for Windows 8","author":"Ramesh","date":"December 3, 2013","format":false,"excerpt":"Some file association settings got mangled in your system? This page contains the default file association settings (.reg files) for some common file types. These fixes are applicable for Windows\u00ae 8 systems only. AVI BAT BMP COM EXE GIF HTM\/HTML ICO JPE\/JPEG\/JPG JS LNK MP3 MPE\/MPEG\/MPG MSC PNG REG SCR\u2026","rel":"","context":"In &quot;Windows 8&quot;","block_context":{"text":"Windows 8","link":"https:\/\/www.winhelponline.com\/blog\/category\/microsoft\/windows\/windows-8\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":1401,"url":"https:\/\/www.winhelponline.com\/blog\/file-association-fixes-windows-10\/","url_meta":{"origin":8452,"position":4},"title":"File Association Fixes for Windows 10 (Defaults)","author":"Ramesh","date":"December 30, 2015","format":false,"excerpt":"Here is the list of file association fixes (Windows defaults) for some of the common file types. These registry fixes are applicable for Windows\u00ae 10 only. AVI IMG TXT BAT INF URL BMP JPE\/JPEG\/JPG VBS CHM JS WMA CMD LNK WMV COM MP3 XML EXE PNG ZIP GIF REG Directory\u2026","rel":"","context":"In &quot;Windows 10&quot;","block_context":{"text":"Windows 10","link":"https:\/\/www.winhelponline.com\/blog\/category\/microsoft\/windows\/windows-10\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":4640,"url":"https:\/\/www.winhelponline.com\/blog\/automatically-clear-temp-files-every-login-using-disk-cleanup-batch-file\/","url_meta":{"origin":8452,"position":5},"title":"Automatically Clear Temp Files Using Disk Cleanup, Storage Sense or Batch file","author":"Ramesh","date":"November 22, 2016","format":false,"excerpt":"The TEMP directory (%temp%) gets bloated over time as applications store data over there and don't always remove the files and folders they created. And, software installers extract the contents of the setup packages to the %temp% folder and fail to do the cleanup act when the installation is complete.\u2026","rel":"","context":"In &quot;Windows&quot;","block_context":{"text":"Windows","link":"https:\/\/www.winhelponline.com\/blog\/category\/microsoft\/windows\/"},"img":{"alt_text":"windows 10 storage settings cleanup options","src":"https:\/\/i0.wp.com\/www.winhelponline.com\/blog\/wp-content\/uploads\/2016\/11\/storage-settings-cleanup-options.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.winhelponline.com\/blog\/wp-content\/uploads\/2016\/11\/storage-settings-cleanup-options.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/www.winhelponline.com\/blog\/wp-content\/uploads\/2016\/11\/storage-settings-cleanup-options.png?resize=525%2C300&ssl=1 1.5x"},"classes":[]}],"_links":{"self":[{"href":"https:\/\/www.winhelponline.com\/blog\/wp-json\/wp\/v2\/posts\/8452","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.winhelponline.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.winhelponline.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.winhelponline.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.winhelponline.com\/blog\/wp-json\/wp\/v2\/comments?post=8452"}],"version-history":[{"count":0,"href":"https:\/\/www.winhelponline.com\/blog\/wp-json\/wp\/v2\/posts\/8452\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.winhelponline.com\/blog\/wp-json\/wp\/v2\/media?parent=8452"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.winhelponline.com\/blog\/wp-json\/wp\/v2\/categories?post=8452"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.winhelponline.com\/blog\/wp-json\/wp\/v2\/tags?post=8452"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}