View Full Version : Problem running a batch file with Scheduled Tasks or at cmd


Peter Chisholm
03-19-2004, 10:12 AM
Cannot run a simple xcopy batch file within Windows 2000
Task Scheduler or as an AT CMD.

If I launch the batch file manually it works fine.

The batch file is "xcopy c:\docume~1\localu~1\mydocu~1\*.*
f:\backup /s /y".

Any ideas would be very welcome.


Regards

Peter Chisholm

Jerold Schulman
03-19-2004, 10:50 AM
On Fri, 19 Mar 2004 02:12:23 -0800, "Peter Chisholm"
<pchisholm@quadrantoffset.co.uk> wrote:

>Cannot run a simple xcopy batch file within Windows 2000
>Task Scheduler or as an AT CMD.
>
>If I launch the batch file manually it works fine.
>
>The batch file is "xcopy c:\docume~1\localu~1\mydocu~1\*.*
>f:\backup /s /y".
>
>Any ideas would be very welcome.
>
>
>Regards
>
>Peter Chisholm


The proper syntax is:

xcopy "c:\docume~1\localu~1\mydocu~1\*.*" f:\backup /s /y

though I would use the real long file names.



Jerold Schulman
Windows: General MVP
JSI, Inc.
http://www.jsiinc.com

Jerold Schulman
03-19-2004, 10:50 AM
On Fri, 19 Mar 2004 02:12:23 -0800, "Peter Chisholm"
<pchisholm@quadrantoffset.co.uk> wrote:

>Cannot run a simple xcopy batch file within Windows 2000
>Task Scheduler or as an AT CMD.
>
>If I launch the batch file manually it works fine.
>
>The batch file is "xcopy c:\docume~1\localu~1\mydocu~1\*.*
>f:\backup /s /y".
>
>Any ideas would be very welcome.
>
>
>Regards
>
>Peter Chisholm


The proper syntax is:

xcopy "c:\docume~1\localu~1\mydocu~1\*.*" f:\backup /s /y

though I would use the real long file names.



Jerold Schulman
Windows: General MVP
JSI, Inc.
http://www.jsiinc.com

Bob I
03-19-2004, 02:15 PM
Is "F" a local drive?

Peter Chisholm wrote:

> Cannot run a simple xcopy batch file within Windows 2000
> Task Scheduler or as an AT CMD.
>
> If I launch the batch file manually it works fine.
>
> The batch file is "xcopy c:\docume~1\localu~1\mydocu~1\*.*
> f:\backup /s /y".
>
> Any ideas would be very welcome.
>
>
> Regards
>
> Peter Chisholm
>

Bob I
03-19-2004, 02:15 PM
Is "F" a local drive?

Peter Chisholm wrote:

> Cannot run a simple xcopy batch file within Windows 2000
> Task Scheduler or as an AT CMD.
>
> If I launch the batch file manually it works fine.
>
> The batch file is "xcopy c:\docume~1\localu~1\mydocu~1\*.*
> f:\backup /s /y".
>
> Any ideas would be very welcome.
>
>
> Regards
>
> Peter Chisholm
>

Matt Hickman
03-20-2004, 03:45 AM
"Peter Chisholm" <pchisholm@quadrantoffset.co.uk> wrote in message news:<104c601c40d9a$ac179d90$a101280a@phx.gbl>...
> Cannot run a simple xcopy batch file within Windows 2000
> Task Scheduler or as an AT CMD.
>
> If I launch the batch file manually it works fine.


Could be a rights issue. Have you checked the Scheduled tasks log?
(advanced -> view log). Redirecting stderr from the batch file into a
file when it is run by the scheduler or at.exe?

Try using the "Run as" property for the scheduled task and
put in an ID with sufficient rights. The credentials for commands
run by at.exe and the task scheduler are not your user credentials
and usually those rights do not extend beyond the local computer.

--
Matt Hickman

Matt Hickman
03-20-2004, 03:45 AM
"Peter Chisholm" <pchisholm@quadrantoffset.co.uk> wrote in message news:<104c601c40d9a$ac179d90$a101280a@phx.gbl>...
> Cannot run a simple xcopy batch file within Windows 2000
> Task Scheduler or as an AT CMD.
>
> If I launch the batch file manually it works fine.


Could be a rights issue. Have you checked the Scheduled tasks log?
(advanced -> view log). Redirecting stderr from the batch file into a
file when it is run by the scheduler or at.exe?

Try using the "Run as" property for the scheduled task and
put in an ID with sufficient rights. The credentials for commands
run by at.exe and the task scheduler are not your user credentials
and usually those rights do not extend beyond the local computer.

--
Matt Hickman

Al Dunbar [MS-MVP]
03-21-2004, 04:16 PM
"Peter Chisholm" <pchisholm@quadrantoffset.co.uk> wrote in message
news:104c601c40d9a$ac179d90$a101280a@phx.gbl...
> Cannot run a simple xcopy batch file within Windows 2000
> Task Scheduler or as an AT CMD.
>
> If I launch the batch file manually it works fine.
>
> The batch file is "xcopy c:\docume~1\localu~1\mydocu~1\*.*
> f:\backup /s /y".

That is not a batch file, that is a command.

/Al

Al Dunbar [MS-MVP]
03-21-2004, 04:16 PM
"Peter Chisholm" <pchisholm@quadrantoffset.co.uk> wrote in message
news:104c601c40d9a$ac179d90$a101280a@phx.gbl...
> Cannot run a simple xcopy batch file within Windows 2000
> Task Scheduler or as an AT CMD.
>
> If I launch the batch file manually it works fine.
>
> The batch file is "xcopy c:\docume~1\localu~1\mydocu~1\*.*
> f:\backup /s /y".

That is not a batch file, that is a command.

/Al

Al Dunbar [MS-MVP]
03-21-2004, 04:23 PM
"Jerold Schulman" <Jerry@jsiinc.com> wrote in message
news:o0kl509d3tlndsrq8h8nr6em84g4h6dlke@4ax.com...
> On Fri, 19 Mar 2004 02:12:23 -0800, "Peter Chisholm"
> <pchisholm@quadrantoffset.co.uk> wrote:
>
> >Cannot run a simple xcopy batch file within Windows 2000
> >Task Scheduler or as an AT CMD.
> >
> >If I launch the batch file manually it works fine.
> >
> >The batch file is "xcopy c:\docume~1\localu~1\mydocu~1\*.*
> >f:\backup /s /y".
> >
> >Any ideas would be very welcome.
> >
> >
> >Regards
> >
> >Peter Chisholm
>
>
> The proper syntax is:
>
> xcopy "c:\docume~1\localu~1\mydocu~1\*.*" f:\backup /s /y
>
> though I would use the real long file names.

I suspect that he quoted the entire command line just to show what it was,
exactly. Note that he says that if he launches the batch file manually it
works fine. Obviously when he launches it manually, he is not using the
double quotes, as that would fail in that context. Most likely he is quoting
it in the AT command, because that is the syntax for AT.

I agree that one should avoid using 8.3 filenames, as these may differ from
workstation to workstation. He would then need to include doubled
double-quotes in the AT command, i.e.:

AT ... "xcopy ""C:\documents and settings\localusername\my
documents\*.*"" F:\backup /s/y"

Matt is probably correct about this being a rights issue. If F: is not a
local drive, but a network drive, that could be an issue as well, as
suggested by Bob.

/Al

Al Dunbar [MS-MVP]
03-21-2004, 04:23 PM
"Jerold Schulman" <Jerry@jsiinc.com> wrote in message
news:o0kl509d3tlndsrq8h8nr6em84g4h6dlke@4ax.com...
> On Fri, 19 Mar 2004 02:12:23 -0800, "Peter Chisholm"
> <pchisholm@quadrantoffset.co.uk> wrote:
>
> >Cannot run a simple xcopy batch file within Windows 2000
> >Task Scheduler or as an AT CMD.
> >
> >If I launch the batch file manually it works fine.
> >
> >The batch file is "xcopy c:\docume~1\localu~1\mydocu~1\*.*
> >f:\backup /s /y".
> >
> >Any ideas would be very welcome.
> >
> >
> >Regards
> >
> >Peter Chisholm
>
>
> The proper syntax is:
>
> xcopy "c:\docume~1\localu~1\mydocu~1\*.*" f:\backup /s /y
>
> though I would use the real long file names.

I suspect that he quoted the entire command line just to show what it was,
exactly. Note that he says that if he launches the batch file manually it
works fine. Obviously when he launches it manually, he is not using the
double quotes, as that would fail in that context. Most likely he is quoting
it in the AT command, because that is the syntax for AT.

I agree that one should avoid using 8.3 filenames, as these may differ from
workstation to workstation. He would then need to include doubled
double-quotes in the AT command, i.e.:

AT ... "xcopy ""C:\documents and settings\localusername\my
documents\*.*"" F:\backup /s/y"

Matt is probably correct about this being a rights issue. If F: is not a
local drive, but a network drive, that could be an issue as well, as
suggested by Bob.

/Al

Ndi
03-22-2004, 10:08 AM
I'd put it all in a .cmd file that runs from anywhere, like

%SystemRoot%\XCopy.exe "c:\docume~1\localu~1\mydocu~1\*" F:\

Note
+ using the environment to make it run from anywhere.
+ you should use the long names, in a quoted string: "C:\Documents and
settings\ ..."
+ you should use * instead of *.*, as that requires them to have a dot, and
not all do. Settings affect this behaviour.
+ schedule the batch, not the command: %comspec% /k "C:\MyBat.bat"

Scheduler has trouble launching .cmd or .bat files, for some reason (mp3
files start just fine?). Scheduling the command interpreter instead does it.
Once it works, schedule it using /c instead of /k, since the command window
will remain open, logged on as SYSTEM.

Alternately, do check the permissions. Schedule cmd.exe to run from
Scheduler (AT), you will be logged as SYSTEM. (echo %username%). Once there,
try to execute the command, see where if fails.

--
Andrei "Ndi" Dobrin
IT Dept, TMA Global
Brainbench MVP
www.brainbench.com

Ndi
03-22-2004, 10:08 AM
I'd put it all in a .cmd file that runs from anywhere, like

%SystemRoot%\XCopy.exe "c:\docume~1\localu~1\mydocu~1\*" F:\

Note
+ using the environment to make it run from anywhere.
+ you should use the long names, in a quoted string: "C:\Documents and
settings\ ..."
+ you should use * instead of *.*, as that requires them to have a dot, and
not all do. Settings affect this behaviour.
+ schedule the batch, not the command: %comspec% /k "C:\MyBat.bat"

Scheduler has trouble launching .cmd or .bat files, for some reason (mp3
files start just fine?). Scheduling the command interpreter instead does it.
Once it works, schedule it using /c instead of /k, since the command window
will remain open, logged on as SYSTEM.

Alternately, do check the permissions. Schedule cmd.exe to run from
Scheduler (AT), you will be logged as SYSTEM. (echo %username%). Once there,
try to execute the command, see where if fails.

--
Andrei "Ndi" Dobrin
IT Dept, TMA Global
Brainbench MVP
www.brainbench.com