[SOLVED] Batch file commands not executed

fcoulomb

Honorable
Jun 30, 2012
9
0
10,510
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 ?
 

fcoulomb

Honorable
Jun 30, 2012
9
0
10,510
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:
[cpp]
REM Backup MUSIC, PHOTOS, VIDEOS to network drive MyBookWorld

perl "C:\Users Data\Francois\PERL\fc_backup.pl" "M:\Music" -l C:\LOGS -f -V "MyBookWorld" -t "\MUSIC MP3"
perl "C:\Users Data\Francois\PERL\fc_backup.pl" "M:\Photos" -l C:\LOGS -f -V "MyBookWorld" -t "\PHOTOS"
perl "C:\Users Data\Francois\PERL\fc_backup.pl" "M:\Videos GoPro" -l C:\LOGS -f -V "MyBookWorld" -t "\VIDEOS GOPRO"

REM Backup OUTLOOK EMAILS to WD USB 2 (USB drive)

REM echo %date:/=%
REM SET newfolder=%date:/=%
REM mkdir "V:\OUTLOOK EMAILS\%newfolder%"
REM xcopy /K "C:\Users\Francois\AppData\Local\Microsoft\Outlook\Outlook.pst" "V:\OUTLOOK EMAILS\%newfolder%"


REM Backup USERS DATA and INETPUB WWWROOT to WD USB 2 (USB drive)

perl "C:\Users Data\Francois\PERL\fc_backup.pl" "C:\Users Data" -l C:\LOGS -f -V "WD USB 2" -t "\USERS DATA\HP6220"
perl "C:\Users Data\Francois\PERL\fc_backup.pl" "C:\inetpub\wwwroot" -l C:\LOGS -f -V "WD USB 2" -t "\INETPUB WWWROOT"

REM Backup MovieMaking to Iomega (USB drive)

perl "C:\Users Data\Francois\PERL\fc_backup.pl" "F:\Film 8mm" -l F:\Logs -f -V "Iomega HDD" -t "\MovieMaking\Film 8mm"
perl "C:\Users Data\Francois\PERL\fc_backup.pl" "F:\Lightscribe" -l F:\Logs -f -V "Iomega HDD" -t "\MovieMaking\Lightscribe"
perl "C:\Users Data\Francois\PERL\fc_backup.pl" "F:\Moto" -l F:\Logs -f -V "Iomega HDD" -t "\MovieMaking\Moto"
perl "C:\Users Data\Francois\PERL\fc_backup.pl" "F:\Movie Maker" -l F:\Logs -f -V "Iomega HDD" -t "\MovieMaking\Movie Maker"
perl "C:\Users Data\Francois\PERL\fc_backup.pl" "F:\Nero 8" -l F:\Logs -f -V "Iomega HDD" -t "\MovieMaking\Nero 8"
perl "C:\Users Data\Francois\PERL\fc_backup.pl" "F:\Pictures" -l F:\Logs -f -V "Iomega HDD" -t "\MovieMaking\Pictures"
perl "C:\Users Data\Francois\PERL\fc_backup.pl" "F:\Studio 12" -l F:\Logs -f -V "Iomega HDD" -t "\MovieMaking\Studio 12"

[/cpp]

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

Guest

Guest


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

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

Tell me if this works for you :)
 
G

Guest

Guest


That's.. not the best idea.. even just to try. I recommend against that idea.
 

fcoulomb

Honorable
Jun 30, 2012
9
0
10,510
I originally opened the command window from within the appropriatre folder:
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:
shortcut_properties.png

and it does.

The advanced properties of the shortcut are greyed out:
shortcut_properties_advanced.png


I then wrote a very simple batch file:
[cpp]echo this is a test
[/cpp]
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.
 

fcoulomb

Honorable
Jun 30, 2012
9
0
10,510
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:
UAC_setting.png

and there is no difference to the behaviour when executing the batch file (or the shortcut).
 
G

Guest

Guest


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?
 
G

Guest

Guest


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

fcoulomb

Honorable
Jun 30, 2012
9
0
10,510


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.

batch_file_not_working.png

 
G

Guest

Guest



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
[cpp]
Windows Registry Editor Version 5.00

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

[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\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}"

[HKEY_CLASSES_ROOT\batfile\ShellEx\{8895b1c6-b41f-4c1c-a562-0d564250836f}]
@="{1531d583-8375-4d3f-b5fb-d23bbd169f22}"


[/cpp]

*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
 

fcoulomb

Honorable
Jun 30, 2012
9
0
10,510
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:
bat_file_association.png


Also, for info, here is the version of Windows 7 that I use:
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.
 
G

Guest

Guest


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
 
G

Guest

Guest

fcoulomb

Honorable
Jun 30, 2012
9
0
10,510


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
 
G

Guest

Guest



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 :)