This question does not appear to be about a specific programming problem, a software algorithm, or softw开发者_运维技巧are tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 3 years ago.
Improve this questionI 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?
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.
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.
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.
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.
Open console as Administrator and type: assoc .bat=batfile
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
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
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.
Check to be sure it is an executable file under the properties security tab.
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.
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]
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.
Just drag and drop the file to command prompt
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.
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):
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.
精彩评论