4

The file extension .cmd somehow got associated with Vim on my Windows 7 machine. When I try to run the cmd file, either by double clicking or running it by typing its name into a command prompt, it opens in Vim. I need to actually run this script.

In the right click menu, there's no "Open With..." or "Run" or anything like that.

The file is shared by many people, so I cannot change it's extension or modify it in anyway.

How can I run this file? (I would consider resetting the file associate back to whatever is default to be an acceptable answer).

Edit: Worth nothing that the CMD file I need to run is on a network machine, which is accessed from an .lnk file on my machine.

5
  • 1
    This has been ask so many times I have these tutorials bookmarked so I can make this comment. Default Programs - Associate a File Type or Protocol - Windows 7 and Default File Type Associations - Restore - Windows 7
    – Ramhound
    May 28, 2015 at 14:08
  • 1
    Those tutorials aren't really helpful in this case. Using those methods, there was no way to change it back to the way it was due to the way Windows handles cmd files. This ultimately required editing the registry to fix. May 28, 2015 at 15:35
  • Going to call you on that, one of those tutorials, has a registry fix for the file extension your asking about so how does that not apply?
    – Ramhound
    May 28, 2015 at 20:35
  • Because it doesn't explain how to do it; it just gives instructions for merging a reg file into the registry. I don't consider that a solution (nor a good practice in general to trust reg files off some website). May 29, 2015 at 11:50
  • I wanted to run config.cmd from CLI rather than GUI. And I could do that by just typing config.cmd in double quotes. Example: C:/u01/somedir/"config.cmd" Nov 16, 2019 at 10:18

1 Answer 1

7

Manual Start:

You could start cmd and passing parameters to start the file. From http://ss64.com/nt/cmd.html:

Options:

/C Run Command and then terminate
Command : The command, program or batch script to be run...

Open up the run command (WIN+R) and type in

cmd /C "Path_to_your_file"

For example:

cmd /C "C:\Users\name\Desktop\script.cmd"

Reset .cmd to cmdfile association

You could also reset the file association of .cmd files to cmdfile, assuming this is what caused your .cmd files to be opened in vim: Start up the cmd as administrator and type

assoc.cmd=cmdfile

Reset registry

This one can cause harm to your computer if you do something wrong since you're working on the registry.

Open up regedit (WIN+R: regedit)

First we want to check if .cmd art associated with cmdfiles.

Goto: HKEY_CLASSES_ROOT\.cmd and check if the (Default) String contains the data cmdfile

Also check if HKEY_CLASSES_ROOT\cmdfile\shell\open\command contains the (Default) String "%1" %*.

If so, go to HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.cmd

.cmd should contain 2 Keys: OpenWithList and OpenWithProgids. If there is an UserChoice key, delete it with all its contents.

The OpenWithList should only contain a (Default) String with an empty value. It should say (value not set). Delete any other values within OpenWithList.

The OpenWithProgids should only contain a (Default) String with an empty value and a binary value with the name cmdfile. Again, delete any other values within OpenWithProgids.

5
  • This doesn't work. The file is still opening up in a text editor. I had to run as cmd /C "C:\Users\me\Script.lnk". The script is actually on a network machine, and cmd / "\\machine\path\to\script.cmd" gave me an error saying UNCs are not supported. May 28, 2015 at 13:59
  • I've updated my answer. Does this help?
    – Zaheylu
    May 28, 2015 at 14:02
  • I tried resetting it using the command assoc.cmd=cmdfile but the issue persists. The file association probably got changed one day when I right clicked->Open With... and forgot to uncheck the "make this the default program" option. May 28, 2015 at 14:13
  • You usually don't have the option 'Open with' on such files, so something must have have gone terribly wrong. I've updated my answer yet again.
    – Zaheylu
    May 28, 2015 at 15:24
  • Editing the registry was unfortunately what ultimately worked. Thank you for the diligence in updating this answer! May 28, 2015 at 15:32

Not the answer you're looking for? Browse other questions tagged or ask your own question.