5

Windows 8 64-bit. The user I'm logged in as has admin rights. When I open a cmd windows the window title even says "Administrator: cmd.exe".

So, I set my .bat file association to have the .bat file opened in Notepad++, and now I can't set it back to run the bat file when I double click on it. I've tried several web pages which told me to edit the registry to no avail.

When I do try to merge a .reg file into my PC, I get an error "You do not have permissions" or something. My user is not "administrator" but my user "chuck" does have admin rights. It always has.

  1. I tried this method, the .reg file merged without error this time, but when I double click on a .bat file it still opens in Notepad++. I downloaded the file to change the .bat file assoc only. Do I have to restart the PC?

  2. I also tried making the registry edits here: click here. It didn't work either.

  3. The .bat file extension cannot be changed in the Associate File Extension with a Program in the Control panel. When I try to associate cmd.exe with a .bat file I get an error like "You cannot associate that program with this file."

  4. I found this link but there is no .bat file entry under FileExts. Also on this link I have no no UserChoice key to delete for HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.b‌​at\UserChoice.

  5. Rebooted PC, I still have the same problem. I will make sure Notepad++ is not restoring associations with itself each time it runs. EDIT: As far as NPP preferences are concerned, it does not register .bat files.

Any more ideas? I have been dealing with this for 3 months off and on now.

NOTE: Some fixes for this problem work on Windows 7 but DO NOT work on Windows 8.


UPDATE: Fixed it. I had to

  1. Make a shortcut to regedt32.exe on my desktop.
  2. Right click shortcut and do "Run As Administrator", even though my user has admin rights.
  3. Search the whole registry for the string "notepad" whereon I found the sneaky little thing here: HKEY_CURRENT_USER\Software\Microsoft\Windows\\**Roaming**\OpenWith\FileExts\\.bat and deleted the UserChoice item.
  4. Reboot windows.
4
  • "Do I have to restart the PC? " Probably, haven't you tried that yet? Commented Jan 3, 2016 at 18:00
  • Yes I rebooted, it didn't help.
    – Bulrush
    Commented Jan 3, 2016 at 18:21
  • @Bulrush Did you read through this with the registry ownship part? TechNet Commented Jan 3, 2016 at 20:11
  • @LMFAO_A_JOKE: Yes. I have no "user choice" in the registry path specified. The solutions that work for Windows 7 don't seem to work for Windows 8.
    – Bulrush
    Commented Jan 5, 2016 at 16:19

3 Answers 3

5

Restoring cmd, bat and exe associations work differently from other file types.

To restore these, run CMD.EXE as Administrator, then:

Microsoft Windows [Version 6.0.6003]
Copyright (c) 2006 Microsoft Corporation.  All rights reserved.

C:\Windows\system32>assoc .bat=exefile
.bat=exefile

C:\Windows\system32>assoc .cmd=exefile
.cmd=exefile

That's it!

3
  • I'm not sure if this is correct, since the default association of .bat is batfile, not exefile. But this worked for me and nothing else. So definitely a good workaround. Commented Feb 16, 2021 at 13:43
  • 1
    Although this actually works as written it's not a good idea to do it this way as it builds a faulty mental model. ASSOC is the command and .bat is the parameter. So it should be assoc .bat=..etc and not assoc.bat=...etc. But: cool! I didn't know about this particular CMD bug. ;-) Commented Jan 21, 2022 at 16:57
  • Thank you. It worked well for me. It is simple and fast.
    – Fatih
    Commented May 5, 2022 at 17:23
4

I have the same problem on Windows 10. I solved it by following the steps below.

  1. run regedit with admin privilege. on Windows 10, open any Explorer window (i.e., file folder), press 'Alt-F S A' (without the quote nor the spaces), and PowerShell window will open. type 'regedit', then return. the regedit window will open.
  2. go to \HKEY_CURRENT_USER\Software\Microsoft.
  3. search for '.bat', specifying that whole field must be the same. on my computer it happens to be at: \HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts.bat

  4. verify that there is a 'UserChoice', which specifies the editor or whatever you specified.

  5. remove 'UserChoice'.
  6. exit regedit.

Now double click on any .bat file and it should run.

I did not need to restart my PC, which runs Windows 10.

3
  • will someone please add a Windows-10 tag please?
    – user817540
    Commented Nov 19, 2017 at 0:56
  • doesn't work for Windows Server 2012
    – Toolkit
    Commented Jun 2, 2019 at 6:34
  • @user817540 at the end of regedit path, although you wrote "FileExts\.bat" it is rendered on browser as "FileExts.bat". Another \ may help. I could not edit it, as minimum edit character count is 6. Commented Sep 7, 2023 at 5:12
0

This assumes you are an administrator

You can set associations from the command line start->run->enter 'cmd' (no quotes) and press enter

Then type

cmd /c assoc .bat

This will give you the filetype the OS thinks a .bat file is/does/whatever

cmd /c ftype batfile

This will give you the command which runs when you 'execute' the file - assuming that the first command returns '.bat=batfile' you need to set the association and you do so with this command

Ftype batfile="%1" %*
4
  • I did this and it didn't work though I haven't rebooted yet. Thank you.
    – Bulrush
    Commented Jan 6, 2016 at 15:13
  • Did it work after a reboot?
    – Junkiebev
    Commented Jan 6, 2016 at 23:15
  • 1
    Rebooted, and it still didn't work. .BAT files are still associated with opening up in Notepad. I wonder if I have to make "Run" the default action instead of "Edit".
    – Bulrush
    Commented Jan 7, 2016 at 13:23
  • 1
    Sorry, .BAT files still open up in Notepad++ after reboot.
    – Bulrush
    Commented Jan 8, 2016 at 15:46

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .