Reassociate Batch Files with Cmd.exe

12,027

Solution 1

This has the reg file downloads for all the default file extensions. Just download the bat one and run it, this should restore all the associations back to default.

http://www.sevenforums.com/tutorials/19449-default-file-type-associations-restore.html

Note: Although it says it is only for Win7 it should be fine for vista as well.

Default_BAT.reg copy in case link dies:

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]

Solution 2

Using regedit.exe, look for the key

.bat 

under

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

and delete it.

EDIT: Also, this

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT.bat] @="batfile"

[HKEY_CLASSES_ROOT.bat\PersistentHandler] @="{5e941d80-bf96-11cd-b579-08002b30bfeb}"

[HKEY_CLASSES_ROOT\batfile\shell\open\command] @="\"%1\" %*"

from http://social.technet.microsoft.com/Forums/en/w7itprogeneral/thread/fc2ca91d-5509-4c9b-92a5-5af19375e361

No longer have a problem with this myself but looked up the above anyway :) !

Solution 3

Merging a .reg file or editing the registry manually is the most reliable option, but perhaps you could simply run assoc .bat= from an admin command prompt.

If neither works, perhaps Windows is hiding file extensions from you and it's actually a .bat.txt file. Uncheck "Hide extensions for known file types" in File Explorer Options (formerly known as Folder Options) and rename the file.

Share:
12,027
Rustavore
Author by

Rustavore

I'm a full stack web developer curious about rust-lang.

Updated on June 21, 2022

Comments

  • Rustavore
    Rustavore almost 2 years

    I installed gvim on windows vista and got really excited to edit EVERYTHING with it. I associated .bat files with gvim, and now I can't get bat files to run... oops!! Could anyone explain how to reassociate .bat files with cmd.exe so that double clicking on them will make them just run?

    EDIT: I followed Jim's advice below by deleting the registry key. After restart bat files are still opening in my text editor. I double checked my registry, and the key had been recreated. I then discovered that the text editor was set in Control Panel > Default Programs > Associate a filetype. I changed bat files to open with the Cmd.exe, but Cmd.exe just opens without running the batch file. I'm guessing the problem is still in the registry.

  • Rustavore
    Rustavore about 12 years
    Thanks, Jim! I found this key, but it's still opening in my text editor. Maybe I just need a restart.
  • Rustavore
    Rustavore about 12 years
    Still not working. I've edited the question with more information.
  • Rustavore
    Rustavore about 12 years
    Worked like a charm! Thanks, Bali C
  • mightypile
    mightypile about 10 years
    I have the same problem as GitNinja, but with a different text editor. I normally would prefer an explanation of the steps over a link to another site, but I reviewed the reg file at sevenforums.com and realized it would require a long explanation of the registry's structure to do that. I looked through my own registry for differences, then ran it. It worked perfectly for me on Win8.1Pro to solve the problem.
  • Cees Timmerman
    Cees Timmerman over 8 years
    According to this answer, only the last line is needed.
  • Math1000
    Math1000 over 8 years
    +1, this actually solves the problem unlike the common suggestion of just changing HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\‌​Explorer\FileExts\.B‌​AT\UserChoice
  • Ridcully
    Ridcully almost 5 years
    assoc .bat= worked perfectly for me (on Windows 10). Thank you.