RDP xcopy failing when logged off

I have a dos batch file that runs on a local server that connects to outside servers, maps a drive with net use, and copies files using xcopy.  The batch file is scheduled to run using Windows.
I connect to the local server (Windows 2003) using RDP on my local machine (Vista).  The batch file runs perfectly as long as I stay logged on to RDP, but as soon as my session expires or I log off, the xcopy command stops working.
rasdial "Customer VPN" xxx xxxxxx
@echo VPN connection had a return code of %errorlevel% >> c:\log.txt
net use x: \\xx.x.x.x\custdata /user:domain\xxx xxxxxx
@echo Net Use had a return code of %errorlevel% >> c:\log.txt
xcopy f:\mydata\data\task.dbf x:\customer\Data /y
@echo Task dbf file copy had a return code of %errorlevel% >> c:\log.txt

When logged in all return codes are zero.  When logged off all are zero except the last one, the xcopy has a return code of 4.

F:\ is a local drive mapped on my local server.  I am wondering if RDP is not keeping that drive mapped when logged off, or the local server is not keeping it mapped when logged off, or if there is something else wrong?
Some additional info:  My company had a server crash (not the one I'm using) a while back and everything worked perfectly before that.  At that time the server I was using became the main production server and my processes were temporarily stopped for a couple of months.  When I recently started these processes again is when my issue showed up.  So the possibility exists that something was changed from an admin point of view on the server regarding RDP/drive mappings.

I need to be logged off and have the xcopy work correctly.  My current workaround is to stay logged on all day long, but if I'm away from my desk for any extended period of time, my session times out and the copy fails.

Thanks for your help.
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

The scheduled task with what credentials run?

Hope this helps.
wigmeisterAuthor Commented:
The scheduled dos batch file runs under my id in Windows Scheduled Tasks.  It doesn't run under admin.  It runs every half-hour and the code in my question write-up is part of the code in that dos batch file.  Not sure if that is what you were asking for or not.  
Yes, that's what i was asking for but I don't know why it's not working...

The error is "4 - Initialization error occurred. There is not enough memory or disk space, or you entered an invalid drive name or invalid syntax on the command line."

I understand that it's "path not found", it seems that it can't map the network drive and xcopy fails...

I'm sorry but I don't know how to fix it.

Good luck.
Protecting & Securing Your Critical Data

Considering 93 percent of companies file for bankruptcy within 12 months of a disaster that blocked access to their data for 10 days or more, planning for the worst is just smart business. Learn how Acronis Backup integrates security at every stage

Steve KnightIT ConsultancyCommented:
When you say that F:\ is a local drive mapped on my local server if this is to another resource on your domain best bet is to use the UNC path - if a user is logged in to the server then it will have drives mapped under it's login but if logged off then there will be no mapped drives.


@echo off
rasdial "Customer VPN" xxx xxxxxx
@echo VPN connection had a return code of %errorlevel% >> c:\log.txt
net use x: \\xx.x.x.x\custdata /user:domain\xxx xxxxxx 2>> c:\log.txt
@echo Net Use had a return code of %errorlevel% >> c:\log.txt
xcopy \\server\share\myata\data\task.dbf x:\customer\Data /d /y 2>> c:\log.txt
@echo Task dbf file copy had a return code of %errorlevel% >> c:\log.txt
net use x: /delete

The /d on xcopy will not copy it unless it has changed which may be approriate too and the 2>> will redirect any error output from those commands to the log too.


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
wigmeisterAuthor Commented:
Saved me again, Dragon!  Thank you very much.
Steve KnightIT ConsultancyCommented:
No problem... and thankyou.  Your points have tipped me over into being a "Sage" in Windows Batch scripting... whatever one of those is!!

You have achieved Sage Certification in Windows Batch Scripting by earning 501,692 points!  To celebrate your new rank, Experts Exchange would like to send you a free official Experts Exchange certified Shirt.

        Windows Batch Scripting
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Server OS

From novice to tech pro — start learning today.