35

I use WinXP sp3, and I have created a .bat file that does something. When I double click on it, a Notepad is opened and I can edit the batch file - but it is not run ??!?!

I expect that when I double click a .bat file - it should run, no? How can I fix this?

1
  • This question was migrated to superuser back in 2009 and it has more info there. Commented Sep 4, 2017 at 9:28

16 Answers 16

38

Check if you have this key in your registry :

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

if you have one it means that the .bat extension is currently associated with notepad (or another program defined by the "Progid" key under this node).

Backup you registry and remove this .bat "UserChoice" node.

your .bat files should then run normally.

Sign up to request clarification or add additional context in comments.

4 Comments

They still open in notepad++
This is actually kind of funny. It's trivially easy to screw up your system by making batch files no longer work properly--simply right-click, "Open with", "Choose default program", and then whatever you choose, if you leave "Always use the selected program..." check (it's checked by default!), you're in trouble once you hit "OK". But the easiest way to undo this is to go in and manually edit the registry--of course.
This worked for me, I guess @MarcinKonradCeglarek. But not until uninstalling notepad++, so I'm wondering if the uninstall would work by itself.
This worked for me. Didn't have the UserChoice node, but deleted .bat node altogether. I noticed there is no node for .cmd. (was working fine for .cmd files)
24

Another common mistake is to have "hide extensions of known file types" set, meaning that although the file name says

"----.bat"

it is really

"-----.bat.txt".

You need to go into "Folder Options --> View Options" to untick this.

3 Comments

It's still easily seen in the icon and the listed type. I don't particularly consider it a mistake not to clear that option.
It is .bat file, not a .txt one
that was my problem. gets me everytime i do a fresh install of windows.
24

check assoc and ftype. By default this should look like:

C:\>assoc .bat .bat=batfile C:\>ftype batfile batfile="%1" %* 

If it's not, see assoc /? and ftype /? how to change it.

3 Comments

Simple and effective, and no messing with registry. Wasn't even aware of the existence of assoc and ftype commands till now. So this answer not only helped me, but also taught me something new. Many thanks.
So the fix was to type: ASSOC .bat=batfile from C:\> prompt. Before running this command, typing:assoc .bat returned .bat=Notepad++_file. After running the fix, assoc .bat returned .bat=batfile. I presume my .bat files will work as expected now.. :-)
As per superuser.com/a/1273182/659759, you may want to do the same thing for .cmd files. If assoc .cmd returns Notepad++_file, you might want to also run assoc .cmd=batfile. I did not find it important to change ftype for either file type though. I am fine typing the full filename with extension when I need to run a .bat or .cmd file. Also, I always show filetypes. Note: When opening your cmd or git bash window to run this command, you may need to do so via Run as Administrator.
22

I had a similar problem on Windows 10, all bat files opened with Notepad++.

I resolved it by going to HKEY_LOCAL_MACHINE\SOFTWARE\Classes\.bat and changing the Data value from Notepad++_file to batfile

This solution fixes the problem on Windows 7 as well.

1 Comment

This one worked for me - just wish I could change the icon as well :)
12

Open console as Administrator and type: assoc .bat=batfile

1 Comment

This worked for me and is the cleanest solution. (Like many I had associated it with Notepad++ via its association settings.)
1

In reverse of the original question, I wanted double click to open .cmd & .bat files in an editor.

I've used:

assoc .cmd="C:\Program Files (x86)\Notepad++\notepad++.exe" ftype cmdfile="C:\Program Files (x86)\Notepad++\notepad++.exe" %1 

So double clicking on a .cmd file opens in a chosen editor

1 Comment

So, after this... how you run (=execute) the cmd file ?
1

I had this issue a few days and in my case, my company PC had different registry configuration for each user. When I was tried to launch the regedit, cmd, or Chrome it got opened by Notepad++.

So my solution was to:

start cmd via taskmannager press control and click that will open a cmd for your current logged user. if you run this command "assoc | findstr /i "txtfile" you will see that .exe is associated with txtfile besides exefile

if you are in a company PC, log your current opened cmd with the system admin user by this command "runas /user:USERADMINOFYOURCORP cmd.exe" and insert the password

then launch the regedit and search for in case that you are the admin of your PC

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

else

-HKEY_USERS{YOUR USER IN THE PC}\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts.exe you will see that it's set to the txtfile.

So create this file with the name exefixer.reg

Windows Registry Editor Version 5.00

[-HKEY_USERS{YOUR USER IN THE PC}\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts.exe]

[-HKEY_USERS{YOUR USER IN THE PC}\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts.exe]

[-HKEY_USERS{YOUR USER IN THE PC}\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts.exe\OpenWithList]

[-HKEY_USERS{YOUR USER IN THE PC}\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts.exe\OpenWithProgids] "exefile"=hex(0): run it from the cmd

Comments

0

Try right clicking it, hovering over "open with" and selecting "command prompt".

As a developer of batch files, windows opens .bat with notepad by default. Someone who doesn't write them will probably by default launch the file with the command line.

2 Comments

There is no Open With.. option in context menu for this .bat file
If the file is associated with Notepad++, for example, Run as Administrator and Open With are NOT options !! I found @Stephen solution above to work perfectly! :-)
0

Check to be sure it is an executable file under the properties security tab.

1 Comment

Yes it is. It is still opened by notepad++
0

In my case none of the answers worked, because i have Notepad ++ as text editor and the .bat file was associated to it. Hence if you use Notepad ++ open it and go to:

Configuration / Preferences / File Association

and remove the .bat entry from the Registered Extensions.

Comments

0

Save the following code as a .REG file, by adding the following code in a new text document.
Don't forget to remove the .txt when you save it!
Right-click and Merge the new .REG file.
That's all! Tested & working:

 Windows Registry Editor Version 5.00 ; Created by: Shawn Brink ; http://www.sevenforums.com ; Tutorial: http://www.sevenforums.com/tutorials/19449-default-file-type-associations-restore.html [-HKEY_CLASSES_ROOT\.bat] [HKEY_CLASSES_ROOT\.bat] @="batfile" [HKEY_CLASSES_ROOT\.bat\PersistentHandler] @="{ 5e941d80-bf96-11cd-b579-08002b30bfeb } " [HKEY_CLASSES_ROOT\batfile] @="Windows Batch File" "EditFlags"=hex:30,04,00,00 "FriendlyTypeName"=hex(2):40,00,25,00,53,00,79,00,73,00,74,00,65,00,6d,00,52,\ 00,6f,00,6f,00,74,00,25,00,5c,00,53,00,79,00,73,00,74,00,65,00,6d,00,33,00,\ 32,00,5c,00,61,00,63,00,70,00,70,00,61,00,67,00,65,00,2e,00,64,00,6c,00,6c,\ 00,2c,00,2d,00,36,00,30,00,30,00,32,00,00,00 [HKEY_CLASSES_ROOT\batfile\DefaultIcon] @=hex(2):25,00,53,00,79,00,73,00,74,00,65,00,6d,00,52,00,6f,00,6f,00,74,00,25,\ 00,5c,00,53,00,79,00,73,00,74,00,65,00,6d,00,33,00,32,00,5c,00,69,00,6d,00,\ 61,00,67,00,65,00,72,00,65,00,73,00,2e,00,64,00,6c,00,6c,00,2c,00,2d,00,36,\ 00,38,00,00,00 [HKEY_CLASSES_ROOT\batfile\shell] @="" [HKEY_CLASSES_ROOT\batfile\shell\edit\command] @=hex(2):25,00,53,00,79,00,73,00,74,00,65,00,6d,00,52,00,6f,00,6f,00,74,00,25,\ 00,5c,00,53,00,79,00,73,00,74,00,65,00,6d,00,33,00,32,00,5c,00,4e,00,4f,00,\ 54,00,45,00,50,00,41,00,44,00,2e,00,45,00,58,00,45,00,20,00,25,00,31,00,00,\ 00 [HKEY_CLASSES_ROOT\batfile\shell\open] "EditFlags"=hex:00,00,00,00 [HKEY_CLASSES_ROOT\batfile\shell\open\command] @="\"%1\" %*" [HKEY_CLASSES_ROOT\batfile\shell\print] [HKEY_CLASSES_ROOT\batfile\shell\print\command] @=hex(2):25,00,53,00,79,00,73,00,74,00,65,00,6d,00,52,00,6f,00,6f,00,74,00,25,\ 00,5c,00,53,00,79,00,73,00,74,00,65,00,6d,00,33,00,32,00,5c,00,4e,00,4f,00,\ 54,00,45,00,50,00,41,00,44,00,2e,00,45,00,58,00,45,00,20,00,2f,00,70,00,20,\ 00,25,00,31,00,00,00 [HKEY_CLASSES_ROOT\batfile\shell\runas] "HasLUAShield"="" [HKEY_CLASSES_ROOT\batfile\shell\runas\command] @=hex(2):25,00,53,00,79,00,73,00,74,00,65,00,6d,00,52,00,6f,00,6f,00,74,00,25,\ 00,5c,00,53,00,79,00,73,00,74,00,65,00,6d,00,33,00,32,00,5c,00,63,00,6d,00,\ 64,00,2e,00,65,00,78,00,65,00,20,00,2f,00,43,00,20,00,22,00,25,00,31,00,22,\ 00,20,00,25,00,2a,00,00,00 [HKEY_CLASSES_ROOT\batfile\shell\runasuser] @="@shell32.dll,-50944" "Extended"="" "SuppressionPolicyEx"="{ F211AA05-D4DF-4370-A2A0-9F19C09756A7 } " [HKEY_CLASSES_ROOT\batfile\shell\runasuser\command] "DelegateExecute"="{ ea72d00e-4960-42fa-ba92-7792a7944c1d } " [HKEY_CLASSES_ROOT\batfile\ShellEx] [HKEY_CLASSES_ROOT\batfile\ShellEx\ContextMenuHandlers] @="Compatibility" [HKEY_CLASSES_ROOT\batfile\ShellEx\ContextMenuHandlers\Compatibility] @="{ 1d27f844-3a1f-4410-85ac-14651078412d } " [HKEY_CLASSES_ROOT\batfile\ShellEx\DropHandler] @="{ 86C86720-42A0-1069-A2E8-08002B30309D } " [-HKEY_CLASSES_ROOT\SystemFileAssociations\.bat] [-HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.bat] 

Comments

0

My solution: delete this registry entry:

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

After the reboot check your file associations again. It should now show Name =.bat, Description=Windows Batch File, Current Default=Unknown application. With this association your bat files should execute normally.

2 Comments

Did remove the entry. .Bat files are still opened by notepad++
This worked for me.
-2

Just drag and drop the file to command prompt

2 Comments

It still opens bat file in notepad++
This may have received a bunch of downvotes but it's just worked for me on my corporate dev Win7 box. Guess it depends how the .bat -> Notepad intercept has been done. Mine might be related to a recent McAffee install.
-2

I was struggling from the last two days, i have gone through the many post and almost every where telling the same thing go through the below and delete the file
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts.bat\UserChoice, but in my Registry i could not Find out the FileExts then finally i got the solution. click on the below link http://www.sevenforums.com/tutorials/19449-default-file-type-associations-restore.html select the BAT Option click the bat link, exe will be download run the downloaded exe. Restart the system it will work fine.

Comments

-2

Windows 7 does that crap all the time.

Best to keep a handy-dandy lil .reg file around to fix it - easier and simpler than having to go edit the registry every time.

Copy this - paste in notepad - give it a filename you can remember so you'll know what it does and what it's for, and when you paste it into notepad, make sure you don't have any extra spaces or carriage-returns. doesn't 'always' affect it, but i've seen it fewk up on people a time er two:

----------everything below this line - do not include this line----------

Windows Registry Editor Version 5.00 [HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.BAT] [HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.BAT\OpenWithList] [HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.BAT\OpenWithProgids] "batfile"=hex(0): 

Comments

-2

I see your problem.

Your batch file may not be saved with the .bat extension.

If you are editing a batch file in Notepad: try this:

Go to the section: Format (Mac) or Save File As (Windows)

Find the drop down box with the format shown [in this case, Text Document (.txt)].

Click the box and find All Files. Click it to replace so that you can save it to a batch file (or any file extension you want).

Clear the text box and type filename.bat. (Replace "filename" with a name of your choice.)

For Notepad++ users:

Go to the Languages section.

Find Batch.

Save the file, and it should be saved as a .bat file.

Hoping this one solved quite everyone's problems!

If not, I'm pretty sure you have a problem with your default file associations. Fortunately, there is a way to fix that.

Right click on your batch file and click Properties.

Look for "Opens With."

Look for a button that lets you change the program to open the file. Click that.

Most probably you won't find CMD there, so hit Browse, and you should land upon Program Files [or Program Files (x86/64), depending on which architecture you are at].

Get out of Program Files and find Windows\System32.

Hit that search bar and type "cmd".

Double click CMD, and it should be chosen as default program for all .bat files.

The next time you want to edit your files in a text editor, right click the file and choose "Edit with Notepad++" or "Edit".

Hope this helped.

1 Comment

Setting it to cmd.exe did not work for me - clicking on the files did not cause them to run

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.