Reputation: 563
I have written a batch file from a VB.NET program I'm creating.
When I double click on the file in Windows XP it brings up a Command Prompt and appears to be running over and over again.
My batch file is as follows
REG ADD "HKCU\Software\Classes\*\shell\Open Folder In Rename" /ve /t REG_SZ /d "Open With Rename" /f
REG ADD "HKCU\Software\Classes\*\shell\Open Folder In Rename\Command" /ve /t REG_SZ /d "P:\Misc\Rename v2.0\Rename v2.0\bin\Debug\Rename v2.0.exe ""%1""" /f
EXIT
I can't understan what I've done wrong, but if I open a command prompt and run it from there, it runs once.
Any help would be gratly appreciated!
Thanks
Upvotes: 36
Views: 40140
Reputation: 10275
In Windows, if you have a command line executable with the same name as your bat filename, and the batch file contains this command, the batch file keeps looping since Windows will execute that .bat
file instead of the Windows command.
Example:
net.bat
on your desktop.net
Double-click the file, and it will keep looping.
The cause of this behaviour is the order of execution of the commands. The command you want to execute is in one of the folders in your path. But the batch file is in your current folder, so it gets executed first, causing the loop.
Upvotes: 99
Reputation: 5271
In Windows Terminal and DOS, to start a program, you only have to specify the filename without extension (such as .bat
, .exe
, .cmd
, .com
). Also, it is case-insensitive.
So if you create a batch file and execute REG
, the system will first look in the current directory for something like reg.exe
or reg.bat
(or another executable with that name). Casing is ignored, so it will include REG.exe
. If it doesn't find it, then it will look in the directories specified in the %PATH%
environment variable.
In your case, you (assumingly) have an exetable named reg.bat
in which you specify that it should call REG
. So it will try to call itself, because it will first look in the current directory, in which it will find itself with that name.
The easiest fix is to use the full filename+extension instead. So you can simply change
REG ADD "HKCU\Software\Classes\*\shell\Open Folder In Rename" /ve /t REG_SZ /d "Open With Rename" /f
to
REG.exe ADD "HKCU\Software\Classes\*\shell\Open Folder In Rename" /ve /t REG_SZ /d "Open With Rename" /f
Upvotes: 0
Reputation: 724
In windows command line if you want to execute a command or a set of commands then we usually put those commands into a .bat file to execute them at any point of time but we must follow some guidelines before doing so.
Upvotes: 5
Reputation: 526
make sure:
your script is not named like a build-in command or programm
make sure the scripts your script calls are not named like a build-in command or programm
e.g. if your script is called: reeeeeboooot.bat that calls shutdown -t 10 -r, but in the SAME FOLDER resides a shutdown.cmd
reeeeeboooot.bat will actually call shutdown.cmd INSTEAD of the build-in command.
sometimes the easiest things are the hardest. (pretty often actually :-D)
Upvotes: 9