Sign in with
Sign up | Sign in
Your question

[SOLVED] Batch file commands not executed

Last response: in Windows 7
Share
June 30, 2012 2:57:37 PM

Hi,
I have a batch file (.bat) that contains 29 lines of commands and REMarks.
When I double click on the file name, a command window opens but nothing is executed (commands or REMarks).
Within the opened command window (cmd.exe), if I type the name of the batch file followed by RETurn, the commands are executed normally.

This used to work under XP and I can'tremember if I ever got it to work since switching to Windows 7.

Any idea why the batch file (or the shortcut version) just opens a ommand windowbut does not seem to read and execute the contents ?
a b $ Windows 7
June 30, 2012 5:14:41 PM

try right clicking the batch file and run as administrator
June 30, 2012 7:28:37 PM

No, the option "Run as administrator" is not in the menu.
I am logged in as an administrator and I work on the PC as administrator all the time.


There is no problem with the file itself and the commands all execute properly when - and only when - I execute the file from within a command window.

Executing the batch file (or the shortcut) from Windows Explorer just opens a command window but does not run the commands within the batch file.

After reading other questions and answers in various forums, I thought at one time it may be linked to the option "run as administrator" and I do have the same problem as other people in not being able to set the "run as administrator" flag on the shortcut (using the properties): the flag is unchecked and greyed out.

The batch file is stored in a user folder on disk C and I am the owner of the file and have full control. I don't think the problem is linked to permissions or security settings as there is no request to "run as administrator" when it executes and a command window does open.

For info, here are the contents of the batch file:
  1. REM Backup MUSIC, PHOTOS, VIDEOS to network drive MyBookWorld
  2.  
  3. perl "C:\Users Data\Francois\PERL\fc_backup.pl" "M:\Music" -l C:\LOGS -f -V "MyBookWorld" -t "\MUSIC MP3"
  4. perl "C:\Users Data\Francois\PERL\fc_backup.pl" "M:\Photos" -l C:\LOGS -f -V "MyBookWorld" -t "\PHOTOS"
  5. perl "C:\Users Data\Francois\PERL\fc_backup.pl" "M:\Videos GoPro" -l C:\LOGS -f -V "MyBookWorld" -t "\VIDEOS GOPRO"
  6.  
  7. REM Backup OUTLOOK EMAILS to WD USB 2 (USB drive)
  8.  
  9. REM echo %date:/=%
  10. REM SET newfolder=%date:/=%
  11. REM mkdir "V:\OUTLOOK EMAILS\%newfolder%"
  12. REM xcopy /K "C:\Users\Francois\AppData\Local\Microsoft\Outlook\Outlook.pst" "V:\OUTLOOK EMAILS\%newfolder%"
  13.  
  14.  
  15. REM Backup USERS DATA and INETPUB WWWROOT to WD USB 2 (USB drive)
  16.  
  17. perl "C:\Users Data\Francois\PERL\fc_backup.pl" "C:\Users Data" -l C:\LOGS -f -V "WD USB 2" -t "\USERS DATA\HP6220"
  18. perl "C:\Users Data\Francois\PERL\fc_backup.pl" "C:\inetpub\wwwroot" -l C:\LOGS -f -V "WD USB 2" -t "\INETPUB WWWROOT"
  19.  
  20. REM Backup MovieMaking to Iomega (USB drive)
  21.  
  22. perl "C:\Users Data\Francois\PERL\fc_backup.pl" "F:\Film 8mm" -l F:\Logs -f -V "Iomega HDD" -t "\MovieMaking\Film 8mm"
  23. perl "C:\Users Data\Francois\PERL\fc_backup.pl" "F:\Lightscribe" -l F:\Logs -f -V "Iomega HDD" -t "\MovieMaking\Lightscribe"
  24. perl "C:\Users Data\Francois\PERL\fc_backup.pl" "F:\Moto" -l F:\Logs -f -V "Iomega HDD" -t "\MovieMaking\Moto"
  25. perl "C:\Users Data\Francois\PERL\fc_backup.pl" "F:\Movie Maker" -l F:\Logs -f -V "Iomega HDD" -t "\MovieMaking\Movie Maker"
  26. perl "C:\Users Data\Francois\PERL\fc_backup.pl" "F:\Nero 8" -l F:\Logs -f -V "Iomega HDD" -t "\MovieMaking\Nero 8"
  27. perl "C:\Users Data\Francois\PERL\fc_backup.pl" "F:\Pictures" -l F:\Logs -f -V "Iomega HDD" -t "\MovieMaking\Pictures"
  28. perl "C:\Users Data\Francois\PERL\fc_backup.pl" "F:\Studio 12" -l F:\Logs -f -V "Iomega HDD" -t "\MovieMaking\Studio 12"


As you can see, it consists of a sequence of perl scripts (which work by the way).
Related resources
July 1, 2012 12:24:20 AM

fcoulomb said:
No, the option "Run as administrator" is not in the menu.
I am logged in as an administrator and I work on the PC as administrator all the time.


There is no problem with the file itself and the commands all execute properly when - and only when - I execute the file from within a command window.

Executing the batch file (or the shortcut) from Windows Explorer just opens a command window but does not run the commands within the batch file.

After reading other questions and answers in various forums, I thought at one time it may be linked to the option "run as administrator" and I do have the same problem as other people in not being able to set the "run as administrator" flag on the shortcut (using the properties): the flag is unchecked and greyed out.

The batch file is stored in a user folder on disk C and I am the owner of the file and have full control. I don't think the problem is linked to permissions or security settings as there is no request to "run as administrator" when it executes and a command window does open.

For info, here are the contents of the batch file:
  1. REM Backup MUSIC, PHOTOS, VIDEOS to network drive MyBookWorld
  2.  
  3. perl "C:\Users Data\Francois\PERL\fc_backup.pl" "M:\Music" -l C:\LOGS -f -V "MyBookWorld" -t "\MUSIC MP3"
  4. perl "C:\Users Data\Francois\PERL\fc_backup.pl" "M:\Photos" -l C:\LOGS -f -V "MyBookWorld" -t "\PHOTOS"
  5. perl "C:\Users Data\Francois\PERL\fc_backup.pl" "M:\Videos GoPro" -l C:\LOGS -f -V "MyBookWorld" -t "\VIDEOS GOPRO"
  6.  
  7. REM Backup OUTLOOK EMAILS to WD USB 2 (USB drive)
  8.  
  9. REM echo %date:/=%
  10. REM SET newfolder=%date:/=%
  11. REM mkdir "V:\OUTLOOK EMAILS\%newfolder%"
  12. REM xcopy /K "C:\Users\Francois\AppData\Local\Microsoft\Outlook\Outlook.pst" "V:\OUTLOOK EMAILS\%newfolder%"
  13.  
  14.  
  15. REM Backup USERS DATA and INETPUB WWWROOT to WD USB 2 (USB drive)
  16.  
  17. perl "C:\Users Data\Francois\PERL\fc_backup.pl" "C:\Users Data" -l C:\LOGS -f -V "WD USB 2" -t "\USERS DATA\HP6220"
  18. perl "C:\Users Data\Francois\PERL\fc_backup.pl" "C:\inetpub\wwwroot" -l C:\LOGS -f -V "WD USB 2" -t "\INETPUB WWWROOT"
  19.  
  20. REM Backup MovieMaking to Iomega (USB drive)
  21.  
  22. perl "C:\Users Data\Francois\PERL\fc_backup.pl" "F:\Film 8mm" -l F:\Logs -f -V "Iomega HDD" -t "\MovieMaking\Film 8mm"
  23. perl "C:\Users Data\Francois\PERL\fc_backup.pl" "F:\Lightscribe" -l F:\Logs -f -V "Iomega HDD" -t "\MovieMaking\Lightscribe"
  24. perl "C:\Users Data\Francois\PERL\fc_backup.pl" "F:\Moto" -l F:\Logs -f -V "Iomega HDD" -t "\MovieMaking\Moto"
  25. perl "C:\Users Data\Francois\PERL\fc_backup.pl" "F:\Movie Maker" -l F:\Logs -f -V "Iomega HDD" -t "\MovieMaking\Movie Maker"
  26. perl "C:\Users Data\Francois\PERL\fc_backup.pl" "F:\Nero 8" -l F:\Logs -f -V "Iomega HDD" -t "\MovieMaking\Nero 8"
  27. perl "C:\Users Data\Francois\PERL\fc_backup.pl" "F:\Pictures" -l F:\Logs -f -V "Iomega HDD" -t "\MovieMaking\Pictures"
  28. perl "C:\Users Data\Francois\PERL\fc_backup.pl" "F:\Studio 12" -l F:\Logs -f -V "Iomega HDD" -t "\MovieMaking\Studio 12"


As you can see, it consists of a sequence of perl scripts (which work by the way).


Just a theory but what if you change to the directory of the file then running it?

Example:
  1. cd C:\Users Data\Francois\PERL\
  2. perl fc_backup.pl "M:\Music" -l C:\LOGS -f -V "MyBookWorld" -t "\MUSIC MP3"


Tell me if this works for you :) 
a b $ Windows 7
July 1, 2012 1:46:13 AM

Have you tried turning off UAC?
July 1, 2012 1:58:32 AM

pjmelect said:
Have you tried turning off UAC?


That's.. not the best idea.. even just to try. I recommend against that idea.
July 1, 2012 5:44:42 AM

I originally opened the command window from within the appropriatre folder:


I also made sure the properties of the shortcut were correctly set so that the command window would open in the appropriate folder:

and it does.

The advanced properties of the shortcut are greyed out:


I then wrote a very simple batch file:
  1. echo this is a test

and when I double-click on it, a command window opens but the echo comand is not executed !
So exactly the same behaviour, i.e. the commands are not executed.
July 1, 2012 5:53:08 AM

I agree with Tony Bilby that turning off UAC may not be a good idea.

The thing is, before googling for answers to my problem, UAC was turned off, i.e. lowest setting.
Only when I started scanning the forums did I realize that UAC may be the cause of my problem and I promptly checked what it was set to.
And this is when I found out that it was off.

So the problem I had was already there with UAC off.

Since then, I have turned UAC on:

and there is no difference to the behaviour when executing the batch file (or the shortcut).
July 1, 2012 5:54:05 AM

fcoulomb said:
I originally opened the command window from within the appropriatre folder:
http://dl.dropbox.com/u/57884305/command_window_environment.png

I also made sure the properties of the shortcut were correctly set so that the command window would open in the appropriate folder
and it does.

The advanced properties of the shortcut are greyed out

I then wrote a very simple batch file:
  1. echo this is a test

and when I double-click on it, a command window opens but the echo comand is not executed !
So exactly the same behaviour, i.e. the commands are not executed.


Does it only not work when you run it through a shortcut link? like does it do the commands normally if you launch the .bat directly?
July 1, 2012 5:59:35 AM

fcoulomb said:
I agree with Tony Bilby that turning off UAC may not be a good idea.

The thing is, before googling for answers to my problem, UAC was turned off, i.e. lowest setting.
Only when I started scanning the forums did I realize that UAC may be the cause of my problem and I promptly checked what it was set to.
And this is when I found out that it was off.

So the problem I had was already there with UAC off.

Since then, I have turned UAC on:
and there is no difference to the behaviour when executing the batch file (or the shortcut).


So, are batch files just not working at all for you?
July 1, 2012 6:18:11 AM

TonyBilby said:
So, are batch files just not working at all for you?


That sums it up pretty well.
Always useful to share frustrations then come up with the right diagnosis.

I copied the file test.bat to my desktop and ran it from there.
This results in opening a command window but not executing the command.
Then I executed the batch file from within the command window and that works OK.


July 1, 2012 6:53:15 AM

fcoulomb said:
That sums it up pretty well.
Always useful to share frustrations then come up with the right diagnosis.

I copied the file test.bat to my desktop and ran it from there.
This results in opening a command window but not executing the command.
Then I executed the batch file from within the command window and that works OK.

http://dl.dropbox.com/u/57884305/batch_file_not_working.png



Hmm, Alright, I have a few theories.

First, After a bit of research I came across one answer that talks about Windows 7 RC and if you have that, their fix was to get the final, and make sure all updates have been done.

Second, another resource pointed out that it could be your default file types may be messed up in the registry.
-for the first fix i would suggest going to "control panel" > "default programs" > "Associate a file type or protocol with a program" and changing it to the proper one.. but after checking to see if it's possible it's not so this is what you'd need to do:

open notepad
Paste all of the following code in that notepad
  1. Windows Registry Editor Version 5.00
  2.  
  3. [HKEY_CLASSES_ROOT\batfile]
  4. @="Windows Batch File"
  5. "EditFlags"=hex:30,04,00,00
  6. "FriendlyTypeName"=hex(2):40,00,25,00,53,00,79,00,73,00,74,00,65,00,6d,00,52,\
  7. 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,\
  8. 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,\
  9. 00,2c,00,2d,00,36,00,30,00,30,00,32,00,00,00
  10.  
  11. [HKEY_CLASSES_ROOT\batfile\DefaultIcon]
  12. @=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,\
  13. 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,\
  14. 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,\
  15. 00,38,00,00,00
  16.  
  17. [HKEY_CLASSES_ROOT\batfile\shell]
  18.  
  19. [HKEY_CLASSES_ROOT\batfile\shell\edit]
  20.  
  21. [HKEY_CLASSES_ROOT\batfile\shell\edit\command]
  22. @=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,\
  23. 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,\
  24. 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,\
  25. 00
  26.  
  27. [HKEY_CLASSES_ROOT\batfile\shell\open]
  28. "EditFlags"=hex:00,00,00,00
  29.  
  30. [HKEY_CLASSES_ROOT\batfile\shell\open\command]
  31. @="\"%1\" %*"
  32.  
  33. [HKEY_CLASSES_ROOT\batfile\shell\print]
  34.  
  35. [HKEY_CLASSES_ROOT\batfile\shell\print\command]
  36. @=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,\
  37. 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,\
  38. 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,\
  39. 00,25,00,31,00,00,00
  40.  
  41. [HKEY_CLASSES_ROOT\batfile\shell\runas]
  42. "HasLUAShield"=""
  43.  
  44. [HKEY_CLASSES_ROOT\batfile\shell\runas\command]
  45. @=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,\
  46. 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,\
  47. 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,\
  48. 00,20,00,25,00,2a,00,00,00
  49.  
  50. [HKEY_CLASSES_ROOT\batfile\shell\runasuser]
  51. @="@shell32.dll,-50944"
  52. "Extended"=""
  53. "SuppressionPolicyEx"="{F211AA05-D4DF-4370-A2A0-9F19C09756A7}"
  54.  
  55. [HKEY_CLASSES_ROOT\batfile\shell\runasuser\command]
  56. "DelegateExecute"="{ea72d00e-4960-42fa-ba92-7792a7944c1d}"
  57.  
  58. [HKEY_CLASSES_ROOT\batfile\ShellEx]
  59.  
  60. [HKEY_CLASSES_ROOT\batfile\ShellEx\ContextMenuHandlers]
  61. @="Compatibility"
  62.  
  63. [HKEY_CLASSES_ROOT\batfile\ShellEx\ContextMenuHandlers\Compatibility]
  64. @="{1d27f844-3a1f-4410-85ac-14651078412d}"
  65.  
  66. [HKEY_CLASSES_ROOT\batfile\ShellEx\DropHandler]
  67. @="{86C86720-42A0-1069-A2E8-08002B30309D}"
  68.  
  69. [HKEY_CLASSES_ROOT\batfile\ShellEx\PropertySheetHandlers]
  70.  
  71. [HKEY_CLASSES_ROOT\batfile\ShellEx\PropertySheetHandlers\PifProps]
  72. @="{86F19A00-42A0-1069-A2E9-08002B30309D}"
  73.  
  74. [HKEY_CLASSES_ROOT\batfile\ShellEx\PropertySheetHandlers\ShimLayer Property Page]
  75. @="{513D916F-2A8E-4F51-AEAB-0CBC76FB1AF8}"
  76.  
  77. [HKEY_CLASSES_ROOT\batfile\ShellEx\{8895b1c6-b41f-4c1c-a562-0d564250836f}]
  78. @="{1531d583-8375-4d3f-b5fb-d23bbd169f22}"


*Make sure you have it all* (or steal the pre done file from here http://bit.ly/LGfQ8I :p  )
Save this file as "batchfix.reg"
then run it (it will require a restart so be prepared)

If you could try those ideas and tell me if it fixes it that'd be great :)  So far that's all I've found but if you still have problems after that I'll dig deeper.

Hope that helps,
Tony Bilby


EDIT: yeah, use the pre done file, i didn't think it'd add line numbers making it impossible to copy really :/  Sorry about that
*although you could reply to this post and copy it from the source I suppose lol
July 1, 2012 11:28:34 AM

OK, I'm pretty sure the .bat files are associated to the correct program as a command window opens when I double-click on the file.
I still checked for that and came up with:


Also, for info, here is the version of Windows 7 that I use:


Finally, I must admit that I am wary of editing the registry and try to do it as little as possible.
So it would be a very last resort for me to have to do this.

This does not mean that I do not appreciate the time and effort you are putting in to try and solve my problem.
Hope you'll understand.
July 1, 2012 7:00:48 PM

fcoulomb said:
OK, I'm pretty sure the .bat files are associated to the correct program as a command window opens when I double-click on the file.
I still checked for that and came up with:
http://dl.dropbox.com/u/57884305/bat_file_association.png

Also, for info, here is the version of Windows 7 that I use:
http://dl.dropbox.com/u/57884305/system_info.png

Finally, I must admit that I am wary of editing the registry and try to do it as little as possible.
So it would be a very last resort for me to have to do this.

This does not mean that I do not appreciate the time and effort you are putting in to try and solve my problem.
Hope you'll understand.


Na, It's totally cool and yeah I understand :)  The registry is a dangerous place.

Hmm well have you by any chance:

Made a ghost partition of your system?
Is your Copy of windows Genuine?
Do you use a raid?
and just for the sake of trying everything, could you run a check disk scan:

type: chkdsk C:\ /f /v /x
it's reply with the drive is locked and if you want to schedule it, type "y" and restart your computer for it to run

Thanks,
Tony Bilby
July 1, 2012 7:11:01 PM

fcoulomb said:
OK, I'm pretty sure the .bat files are associated to the correct program as a command window opens when I double-click on the file.
I still checked for that and came up with:
http://dl.dropbox.com/u/57884305/bat_file_association.png


This makes me question though, when i go to my file association it's different then yours. Mine runs perfectly fine.
https://dl.dropbox.com/u/8672632/batchAssociation.PNG

EDIT: This would also explain why it launches CMD Prompt and looks semi-normal.
July 1, 2012 7:31:40 PM

TonyBilby said:
This makes me question though, when i go to my file association it's different then yours. Mine runs perfectly fine.
https://dl.dropbox.com/u/8672632/batchAssociation.PNG

EDIT: This would also explain why it launches CMD Prompt and looks semi-normal.


Brilliant ! Absolutely brilliant.

I have removed the file-to-application association (using a utility found on the net: http://www.winhelponline.com/blog/unassociate-file-types-windows-7-vista/) so that .bat is now associated with "unknown application" and everything works.

THANK YOU for your help in solving this.

François

P.S. Now, how do I mark this problem as "solved" ?
FC
July 1, 2012 7:54:48 PM

fcoulomb said:
Brilliant ! Absolutely brilliant.

I have removed the file-to-application association (using a utility found on the net: http://www.winhelponline.com/blog/unassociate-file-types-windows-7-vista/) so that .bat is now associated with "unknown application" and everything works.

THANK YOU for your help in solving this.

François

P.S. Now, how do I mark this problem as "solved" ?
FC



Glad that worked out for you :)  and you have to choose a post that had the right answer for you as "answered my question" I believe :) 
July 1, 2012 8:03:09 PM

answered my question
July 1, 2012 8:12:34 PM

nvm this message xD
!