75

What do I set the 'Opens with...' property to in order to get the system to run .bat files again (when they are double-clicked)?

Somehow my boss convinced his workstation that the handler for .bat files was supposed to be Word. Now, when double-clicking .bat files, they're opened up in Word.

7
  • 1
    I can't even find .BAT in the file type associations dialog in Windows. And I can't invoke the Open With... dialog on a .bat file. How could he have changed it??
    – Nick Bedford
    Oct 9, 2009 at 1:03
  • 3
    umm...i'm guessing that's why he's da boss? ;)
    – justSteve
    Oct 9, 2009 at 1:12
  • 3
    right click .bat file -> Open with... -> select MS Word, check "Always open with this program", click OK. bam, your extension is now registered to Word. Oct 11, 2009 at 17:21
  • My bat files also don't have the "Open With" menu (Windows 7) Other files have it, of course.
    – lbalazscs
    Jan 16, 2013 at 18:12
  • 1
    FYI, .bat files are not executables. They are interpreted scripts.
    – Keltari
    Jan 17, 2016 at 5:55

12 Answers 12

61

I think you'll have to remove the .bat file association from the registry (using the regedit program).

According to this forum thread on LockerGnome, you need to remove registry settings underneath this key:

HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.bat

You'll probably want to back up registry before doing this, just to be safe.

6
  • 30
    For you minimalists out there, I would add that I was successful by removing only the UserChoice subfolder. Once it was gone, the default Execute behavior was restored. HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.bat\UserChoice Apr 25, 2013 at 17:11
  • I removed the entire .bat key and things came back to normal. For some reason (I suspect antivirus) I couldn't rename the UserChoice key. Jul 1, 2014 at 6:10
  • Such a pain!! and this happened automatically on an update. Thanks a bunch MS.
    – Jus12
    Jul 28, 2015 at 13:28
  • In the path HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.bat I removed the UserChoice key completely, which worked fine for me. @Kim - maybe you did not run regedt32 as administrator (right-click and select Run as administrator)?
    – Matt
    Oct 9, 2015 at 13:43
  • There are many other possible reasons / registry places. See the other answers, and my answer trying a summary.
    – kxr
    Mar 22, 2016 at 14:38
35

This registry key file will do it. Copy and paste to a text file called "restore.reg", and double click it to merge into the registry.

It will clear out any per-user setting you may have accidentlly created for .bat files, and restore the system defaults, including the .bat <-> batfile file type relationship as well as the actual parameters for launching a batfile.

Windows Registry Editor Version 5.00

[-HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.bat]
[-HKEY_CURRENT_USER\Software\Classes\.bat]
[-HKEY_CURRENT_USER\SOFTWARE\Classes\batfile]

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\.bat]
@="batfile"

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\batfile\shell\open\command]
@="\"%1\" %*"
6
  • also had to run for cmd files on my machine
    – mohlsen
    Jan 7, 2011 at 18:17
  • 1
    I used this one, at is seemed to work fine. Mar 9, 2012 at 8:17
  • After doing this, while double clicking bat file, I am getting error like "a.bat is not a valid win32 application"
    – rashok
    Nov 26, 2015 at 1:45
  • Works perfectly but to take affect I had to kill explorer.exe and run as a new task again using Task Manager. Jul 21, 2016 at 23:04
  • This one solved if for me, the selected answer didn't It was still asking for an app to open .bat files.
    – JDuarteDJ
    Apr 21, 2017 at 10:26
14

None of the answers above fixed it for the machine I was working with, but what fixed it was starting an Admin Shell and running

assoc .bat=batfile
assoc .cmd=batfile
7
  • 1
    This is the solution for Win 2008 Server, cmd run as Administrator. No restart of Explorer.exe or Windows required.
    – TonyG
    Jul 6, 2018 at 3:00
  • 4
    This worked for me on Windows 10
    – htxryan
    Mar 18, 2019 at 20:53
  • 1
    With Run as Administrator, this worked perfectly for me on Windows 10 !! :-) Now (install) .exe files that call .bat files work as expected. This solution is much better than having to mess with the registry! As a sidenote, to see what the current association is, simply type assoc .bat In my case both .bat and cmd were associated as Notepad++_file. Now that they are .batfile, right-clicking on bat files allows me to RUN or Run as Administrator. Before this was not possible. Previously, my workaround was to open a cmd window then manually type a filename.bat to run the file Jul 23, 2019 at 21:55
  • 3
    +1. This should be the accepted answer. This is super fast, way safer than digging through the registry, and works for multiple versions of Windows (incl 10). Just make sure you launch in an Admin Shell, as the answer suggests: launch cmd.exe as administrator. Jan 12, 2020 at 0:56
  • 1
    Possibly the code should be assoc .cmd=cmdfile as my quite recent Windows 2016 returns that if I run assoc .cmd. (if you want a full list, just run assoc)
    – LosManos
    May 11, 2020 at 8:12
10

I had the same problem (in Windows 7); batch files were opening in Notepad instead of being executed.

Correcting the below registry for .bat files (as per any other machine where it works) will make the batch execute correctly:

HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\

.bat                --> default-> Value not set
.bat/OpenWithList   --> default-> Value not set
.bat/OpenWithProgIds--> default-> Value not set
                        batfile-> Zero length binary values 

Keep these entries but remove all others under .bat. Refresh and run a batch file by double clicking - it will run correctly.

3

The information in this answer led me to the solution to my question.

I opened the registry key mentioned there and

  • deleted the UserChoice key
  • removed all entries under the OpenWithList key
2

The answer that got 40 votes by Kaleb didn't work for me but I ended up finding the answer. To get the bat file to execute again, you have to go to:

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\.bat] and set (Default) to batfile. If you have batch scripts opening in Word or Notepad++ instead of running on double click, it's because those programs have set (Default) to their own mimes.

If you want a quick fix, just open a text file and paste:

    Windows Registry Editor Version 5.00

    [HKEY_LOCAL_MACHINE\SOFTWARE\Classes\.bat]
    @="batfile"

And save it with a .reg extension and double click to merge.

1
  • If this worked for you, great, but the first place Windows checks is Current User (HKCU) not Local Machine (HKLM). If not found in HKCU it will then check HKLM. Check this answer superuser.com/a/1056014/47628 for more locations.
    – B. Shea
    May 3 at 13:43
1

In the regisrty you .bat entry needs to point to the batfile entry:

[HKEY_CLASSES_ROOT\.bat]
@="batfile"
.....

Naturally you will also need to make sure you have a batfile registry entry:

[HKEY_CLASSES_ROOT\batfile]
@="MS-DOS Batch File"
.....
1

In Windows 8 use Notepad to make or modify a Batch file but the secret is the following:

Save the batch file using double quotes. Literally use "MYBACK.BAT" using the double quotes in the save box to save the file. Instead of MYBACK.BAT

1
  • True (same for previous versions of Windows/Notepad). But how does that answer the question?
    – Arjan
    Jul 29, 2014 at 20:13
1

Again, none of the previous answers did it here.
I for example had to change the default value of [HKEY_LOCAL_MACHINE\SOFTWARE\Classes\batfile\shell] from edit to open.

(Once I had changed the file type extend associations in Explorer folder options dialog. BAT files were & are not offered for change. There seems to be a special exception. But I remember, once I added the BAT type in the Explorer folder options dialog, to get 'edit' being the default shell verb.)

Various places to inspect

So after all there are varying reasons and varying OS version, and (at least) the (default) values of the following registry folders (and subfolders) need to be checked - using some common sense :-). And I think that list may reflect the order of precedence which is relevant to the OS:

[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.bat]  (if present: remove "UserChoice")
[HKEY_CURRENT_USER\Software\Classes\.bat]  (if present: @ = "batfile")
[HKEY_CURRENT_USER\SOFTWARE\Classes\batfile]  (if present)
[HKEY_CURRENT_USER\SOFTWARE\Classes\batfile\shell]  (if present: @ = "open")
[HKEY_CURRENT_USER\SOFTWARE\Classes\batfile\shell\open\command]  (if present: @ = "\"%1\" %*")
[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\.bat]  @ = "batfile"
[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\batfile]
[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\batfile\shell]  @ = "open"
[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\batfile\shell\open\command]  @ = "\"%1\" %*"
[HKEY_CLASSES_ROOT\.bat]  @ = "batfile"
[HKEY_CLASSES_ROOT\batfile]
[HKEY_CLASSES_ROOT\batfile\shell]  @ = "open"
[HKEY_CLASSES_ROOT\batfile\shell\open\command]  @ = "\"%1\" %*"
1
  • Gave you a +1 for listing all the locations and precedence. No one else bothered. (And yes, this is correct order/precedence for file extensions/types.) RE: Classes Root (HKCR): If you update both the HKLM and HKCU and reboot, the HKCR shouldn't need an edit. It should only be a compilation of the two. "On Windows 2000 and above, HKCR is a compilation of user-based HKCU\Software\Classes and machine-based HKLM\Software\Classes." -> en.wikipedia.org/wiki/Windows_Registry#HKEY_CLASSES_ROOT_(HKCR)
    – B. Shea
    May 3 at 13:37
0

The registry contents vary for different Windows versions.

I suggest that you find another computer with the same O/S version, and use regedit to export the contents of HKEY_CLASSES_ROOT\.bat and HKEY_CLASSES_ROOT\batfile.

Then go to the Boss's machine, delete the above two keys and import the two files.

0

To avoid the hassle (and for many people scariness and intimidation) of editing the registry, you could use the free, excellent, and non-invasive repair utility which actually accomplishes any good (versus many other crapware), tweaking.com Windows Repair.

Specifically: install it, skip ahead to the "Repairs" tab, click "Open Repairs," and put a checkmark in "04 Register System Files," then click the "Start Repairs" button.

The user interface of that program has changed over time, so in the future, anyone doing this may need to explore the program to find this option.

I would hazard a guess that a lot of other problems exist on your Boss' computer, so that he may want to run all the program's repairs, which can take hours, depending.

Note: I am not affiliated with tweaking.com; I'm just a big fan of the program. Skilled use of it has saved my computer's operating system or solved stubborn problems multiple times.

0

Rather then registry editing use the safer and more direct command line. From an Adminstrator CMD prompt:

By showing existing association for the file extension we see that on this machine Windows thinks the file belongs to Notepad++:

C:\> assoc .bat
.bat=Notepad++_file

Let's find out what command is run for that association:

C:\> ftype Notepad++_file
Notepad++_file="C:\ProgramData\scoop\apps\notepadplusplus\current\notepad++.exe" "%1"

Search for a different command to run that might be better (-i means ignore-case):

C:\> ftype | findstr -i bat
batfile="%1" %*

Change the association to use this other command:

C:\> assoc .bat=batfile
.bat=batfile

Done.

Notes

This is an improvement of the base answer by @Niklas-R https://superuser.com/a/1273182/16966.

assoc and ftype on their own list everything.
Don't forget the dot! assoc bat and assoc .bat are not the same.
Technically cmd should be assoc .cmd=cmdfile and not batfile, but it doesn't seem to harm or change anything to have them both the same.

Also see:

Not the answer you're looking for? Browse other questions tagged or ask your own question.