Batch files don't run - they're being open

2020-02-23 06:20发布

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?

16条回答
我想做一个坏孩纸
2楼-- · 2020-02-23 06:33

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

查看更多
兄弟一词,经得起流年.
3楼-- · 2020-02-23 06:34

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.

查看更多
祖国的老花朵
4楼-- · 2020-02-23 06:36

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

查看更多
Melony?
5楼-- · 2020-02-23 06:41

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.

查看更多
Explosion°爆炸
6楼-- · 2020-02-23 06:42

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.

查看更多
家丑人穷心不美
7楼-- · 2020-02-23 06:44

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.

查看更多
登录 后发表回答