How do I restore .bat files association with the system (make them run when double-clicked)?

70

22

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

Posted 2009-10-09T01:00:38.677

Reputation: 1 399

1FYI, .bat files are not executables. They are interpreted scripts. – Keltari – 2016-01-17T05:55:47.193

1I 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?? – None – 2009-10-09T01:03:13.373

3umm...i'm guessing that's why he's da boss? ;) – None – 2009-10-09T01:12:08.030

3right click .bat file -> Open with... -> select MS Word, check "Always open with this program", click OK. bam, your extension is now registered to Word. – quack quixote – 2009-10-11T17:21:53.377

My bat files also don't have the "Open With" menu (Windows 7) Other files have it, of course. – lbalazscs – 2013-01-16T18:12:14.850

Possible duplicate of How do you remove a default program association for file types in Windows 7?.

– Peter Mortensen – 2013-09-05T16:03:43.950

Answers

59

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.

Kaleb Brasee

Posted 2009-10-09T01:00:38.677

Reputation: 706

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. – Kim Gräsman – 2014-07-01T06:10:33.780

Such a pain!! and this happened automatically on an update. Thanks a bunch MS. – Jus12 – 2015-07-28T13:28:14.980

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 – 2015-10-09T13:43:38.660

There are many other possible reasons / registry places. See the other answers, and my answer trying a summary. – kxr – 2016-03-22T14:38:26.003

30For 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 – Mark F Guerra – 2013-04-25T17:11:52.130

33

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

Posted 2009-10-09T01:00:38.677

Reputation: 11 212

After doing this, while double clicking bat file, I am getting error like "a.bat is not a valid win32 application" – rashok – 2015-11-26T01:45:43.733

Works perfectly but to take affect I had to kill explorer.exe and run as a new task again using Task Manager. – Dave Anderson – 2016-07-21T23:04:16.787

This one solved if for me, the selected answer didn't It was still asking for an app to open .bat files. – JDuarteDJ – 2017-04-21T10:26:09.057

also had to run for cmd files on my machine – mohlsen – 2011-01-07T18:17:34.063

1I used this one, at is seemed to work fine. – Håkon K. Olafsen – 2012-03-09T08:17:00.673

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.

Dreamer

Posted 2009-10-09T01:00:38.677

Reputation: 101

8

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

Posted 2009-10-09T01:00:38.677

Reputation: 211

1This is the solution for Win 2008 Server, cmd run as Administrator. No restart of Explorer.exe or Windows required. – TonyG – 2018-07-06T03:00:35.980

Do not work????????????????? – YumYumYum – 2019-01-17T11:45:30.347

3This worked for me on Windows 10 – htxryan – 2019-03-18T20:53:07.280

nope, didn't work on Windows Server 2012 – Toolkit – 2019-06-02T06:35:17.690

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 – SherylHohman – 2019-07-23T21:55:18.827

+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. – J.D. Mallen – 2020-01-12T00:56:50.757

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

GreenGiant

Posted 2009-10-09T01:00:38.677

Reputation: 219

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.

thebunnyrules

Posted 2009-10-09T01:00:38.677

Reputation: 510

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

Posted 2009-10-09T01:00:38.677

Reputation: 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

user351257

Posted 2009-10-09T01:00:38.677

Reputation: 11

True (same for previous versions of Windows/Notepad). But how does that answer the question? – Arjan – 2014-07-29T20:13:27.657

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.

r_alex_hall

Posted 2009-10-09T01:00:38.677

Reputation: 325

0

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

Posted 2009-10-09T01:00:38.677

Reputation: 101

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

Posted 2009-10-09T01:00:38.677

Reputation: 306 093