• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 3268
  • Last Modified:

Microsoft, Windows Schedule Task, Windows Server 2003 Standard, Running Forfiles in a batch-file

Computer is a member server running Windows 2003 SVR in an Windows SBS domain.
I have scheduled a simple batch file to run in Windows Schedule Task using the domain\administrator account.
The batch file runs the XCOPY and FORFILES utilities. Objective is to use FORFILES to clean up prior to using XCOPY to backup remaining files to a network share.
It contains the following lines

CD C:\BACKUP
FORFILES -pR:\EXACT\009 -s -m*.* -d-5 -c"CMD /C del @FILE" > filelogr.txt
xcopy "D:\SQL\GoodHealth\MSSQL\BACKUP\009\*.bak" "\\Pc-store\Raid-Backup\Exact\009\" /D /C /F /Y > synclogr.txt

The batch file runs as scheduled. XCOPY works as expected. However, FORFILES fails. The error is that R:\EXACT\009 is not a valid directory. R: is a mapped drive.
But when I run the same batch file whilst logged on as domain\admnistrator, both runs successfully. FORFILES only fails when I run it via the Windows Scheduler.

I have tried using UNC instead of the mapped drive R:. When I did that, FORFILES complained about not supporting UNC.

Any trouble-shooting advice and suggestions would be gratefully received.

Thanks.
0
garychu
Asked:
garychu
  • 3
  • 2
1 Solution
 
SteveGTRCommented:
Don't use a mapped drive in a scheduled task unless you explicitly map it. Use a UNC instead:

R:\EXACT\009

\\server\share\dir

The reason is that the mapped drive you have available under your accounts isn't setup for the user.
0
 
garychuAuthor Commented:
Thanks SteveGTR
I have already tried using a UNC instead of a mapped drive. Unfortunately, the utility (from Microsoft no less) FORFILES does not support UNC. Duh!
0
 
SteveGTRCommented:
Well, well, well...

You could also ways map a network drive then do it:

CD C:\BACKUP

net use z: /del
net use z: \\server\share

FORFILES -pz:\EXACT\009 -s -m*.* -d-5 -c"CMD /C del @FILE" > filelogr.txt
xcopy "D:\SQL\GoodHealth\MSSQL\BACKUP\009\*.bak" "\\Pc-store\Raid-Backup\Exact\009\" /D /C /F /Y > synclogr.txt
0
 
garychuAuthor Commented:
Thanks again SteveGTR.
I had actually thought of doing that earlier. But thought it would be redundant. And a system "error" about the mapped drives already being in use etc might cause the batch file not to complete, unattended.
Well I was wrong. Because I have now tried it and found that it worked.
Thanks for your pointer!
0
 
SteveGTRCommented:
Glad to help and I learned something too about forfiles not supporting UNC's. Very interesting.
0

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now