When you double-click a Windows batch file (
.bat) or a
.cmd file, one of the following symptoms may happen:
- The error “Windows cannot find ‘filename.bat’. Make sure you typed the name correctly, and then try again.” occurs when you run a .bat or a .cmd file.
- The batch file opens a Command Prompt window, but its commands don’t execute.
- Notepad or any other text editor opens the batch file.
The user may have inadvertently associated
.bat files with a text editor, or associated .bat files with
cmd.exe, or tampered with the settings in the registry. Once you set a file association for
.bat 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.
The error Windows cannot find ‘filename.cmd’ or ‘filename.bat’ occurs if the COMSPEC environment variable is incorrect.
Windows Batch file (
.bat) 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.
Step 1: Fix the COMPSPEC variable
If you receive the error “Windows cannot find ‘filename” when running a .bat or a .cmd file, fix the COMSPEC variable.
Open an admin Command Prompt window and run:
setx ComSpec %SystemRoot%\system32\cmd.exe /m
You should see the message SUCCESS: Specified value was saved in the output.
Exit the Command Prompt window.
The above step should fix the error “Windows cannot find ‘filename’ when running .bat or .cmd files.
Step 2: Fix the .BAT file association
To fix symptoms 2 & 3 explained earlier, the .bat file association must be repaired.
Method 1: Use .BAT/.cmd file association registry fix
- Download the .bat fix or .cmd fix for Windows 10/11 from the file association fixes page.
- Unzip the archive and double-click the enclosed registry file.
- Click Yes when you’re asked for confirmation to continue.
- Click OK.
Method 2: Fix the .BAT file association manually
- Start the Registry Editor (
- Go to the following key:
- Set the
(default)value data to
- Go to the following key:
- In the right-pane, make sure that the
(default)value data is not set. It should read as
value not set. In case you see some other text there, then right-click the
(default)value and choose
- Then, proceed to the following key:
(default)and set its value data to:
- Go to the following branch:
The values present under one of its subkeys (
UserChoice) may be causing the problem.
- Right-click on the
.batkey, and choose
Yeswhen prompted for confirmation. Don’t worry! This registry key and its three subkeys are trivial, and they’re only required if you want to override the
.batfile association defaults.
- Exit the Registry Editor.
Automate the above steps using REG file
To automate the steps listed in Method 2 using a REG file, do the following..
- Open Notepad.
- Copy the following lines and paste them into Notepad.
Windows Registry Editor Version 5.00 [HKEY_LOCAL_MACHINE\SOFTWARE\Classes\.bat] @="batfile" [HKEY_LOCAL_MACHINE\SOFTWARE\Classes\batfile\shell] @=- [HKEY_LOCAL_MACHINE\SOFTWARE\Classes\batfile\shell\open\command] @="\"%1\" %*" [-HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.bat]
- Save the file with any name having the
fix_bat.regto apply the configuration in the registry. Click Yes when prompted for confirmation.
That’s it! You’ve now fixed the batch file association settings. Batch files should now execute correctly when double-clicked.
One small request: If you liked this post, please share this?One "tiny" share from you would seriously help a lot with the growth of this blog. Some great suggestions:
- Pin it!
- Share it to your favorite blog + Facebook, Reddit
- Tweet it!