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.

justSteve
  • 1,479

12 Answers12

63

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.

Alois Mahdal
  • 2,344
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\" %*"
Factor Mystic
  • 13,015
19

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
Niklas R
  • 321
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.

Gareth
  • 19,080
Dreamer
  • 101
3

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]
@=&quot;batfile&quot;

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

B. Shea
  • 1,388
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

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\" %*"
kxr
  • 251
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"
.....
user6621
  • 111
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

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:

matt wilkie
  • 5,324
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.

harrymc
  • 498,455