Link to home
Create AccountLog in
Avatar of John_Long
John_Long

asked on

Cannot run batch file

We cannot get a .bat file to run on a user's workstation. When you double click on the shortcut, the command window opens up and shows the path where the batch file is located. If you enter the name of the batch file, it will run. However, it should not require thie extra step.
Avatar of mincftw
mincftw

Under the script place a sentence pause and run the script again.

It shows you what happens while running the script.
Avatar of Paul MacDonald
Are you sure it's not running, then quitting?  

Also (and more likely) is the shortcut correct?  That is, are you sure the shortcut doesn't just point to the folder?  Does the path have spaces in it?  Is the path wrapped in quotes?
It sound like the filetype association for opening & executing a .BAT file has changed from the defaults.

For a really quick fix,  check out this site:
XP File Association Fixes

Download the .BAT fix and run the registry file.

or you can do it manually by

Regedit
Guide to this Key:
HKEY_CLASSES_ROOT\batfile\shell\open\
Make sure the value is as below:
command = \"%1\" %*

If the % is missing, then it will open the Command Windows to the path Only.


The full reg file is enclosed for your convenience.
Create a notepad file save it as batfix.reg
double click it, answer yes to add to registry.

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\.bat]
@="batfile"

[HKEY_CLASSES_ROOT\.bat\PersistentHandler]
@="{5e941d80-bf96-11cd-b579-08002b30bfeb}"

[HKEY_CLASSES_ROOT\batfile]
@="MS-DOS Batch File"
"EditFlags"=hex:30,04,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,73,00,68,00,\
  65,00,6c,00,6c,00,33,00,32,00,2e,00,64,00,6c,00,6c,00,2c,00,2d,00,31,00,35,\
  00,33,00,00,00

[HKEY_CLASSES_ROOT\batfile\shell]

[HKEY_CLASSES_ROOT\batfile\shell\edit]

[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\shellex]

[HKEY_CLASSES_ROOT\batfile\shellex\DropHandler]
@="{86C86720-42A0-1069-A2E8-08002B30309D}"

[HKEY_CLASSES_ROOT\batfile\shellex\PropertySheetHandlers]

[HKEY_CLASSES_ROOT\batfile\shellex\PropertySheetHandlers\PifProps]
@="{86F19A00-42A0-1069-A2E9-08002B30309D}"

[HKEY_CLASSES_ROOT\batfile\shellex\PropertySheetHandlers\ShimLayer Property Page]
@="{513D916F-2A8E-4F51-AEAB-0CBC76FB1AF8}"

Open in new window





Avatar of John_Long

ASKER

The test batch file has only 2 lines in it.
echo "This is a test"
Pause

We created the shortcut by right clicking on the batch and selecting "send to desktop create shortcut"
This batch file and other batch files that we actually want to use run properly on other workstations.
The shortcut creation just points to the batch file.  

For test purposes, have you created and tested any other batch files on this workstation?
Do you receive the same result?

If you receive the same result, then I suggest running the repair I've listed above, then the workstation will be able to run bat files.



I am receiving the same result with all batch files we are trying to run on this workstation.

I have checked the registry and have found the command line  as you have listed. I have checked against other worksations where the batch file works properly and found the command line to be the same. The only difference is that you have shown it as \"%1\" %* whereas the other registries show it as "%1" %*  That is without the slashes. I have tried it both ways and neither has made a difference.
Have you tried renaming the .bat files to .cmd files?
Hi.. try this

http://www.dougknox.com/xp/file_assoc.htm

Download and Run the BAT File Association fix

Good luck!
Never mind... they already sent you that link
is the batch file located on the local computer or on the network.
We have tried running .cmd files no difference.  We have tried the batch file from the local machine and from the network.
What happens if you place the batch file on the desktop?
Do you have any realtime antivirus such as Symantec Endpoint Security or group policies applied to the user or specific machine which could be preventing the execution of a cmd file?

Has this computer been previously infected with malware or a virus?
No group policies that are applied to just this user or machine. We do run Symantec EndPoint Protection on this workstation and all the workstations in our domain. They all have the same setup. We also run Spybot on this workstation but, we run it on many other workstations. We have had malware and viruses on this workstation before but we have cleaned them up.
John,

Try the following:

From a command prompt type the following command;
assoc .bat
should return with
 .bat=batfile
If not
assoc .bat=batfile
to restore the default file type association.

ftype batfile
should return with
batfile="%1" %*
If not
ftype batfile="%1" %*
to restore the default "Open" action for the file type.



ASKER CERTIFIED SOLUTION
Avatar of FirstSentinel
FirstSentinel
Flag of United States of America image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account