[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now


How to copy a file from a network share to a local folder - scheduled automatically

Posted on 2011-09-02
Medium Priority
Last Modified: 2012-05-12
I'd like to somehow schedule a file (access database .mdb file) to be copied from a network share to a local folder on the C drive.  I want this to copy to run on a regular basis (possibly every day, or perhaps each time a user logs in), so that the copy is relatively current.

The network share is restricted to only certain users, so a user does need to be logged in (or identified) in order to copy the access db.

We are working with all Windows systems.  The local systems are all running Windows XP SP3.  Users log in with domain accounts.

I'm not sure how to setup something to run on a regular basis for this purpose.  Any suggestions would be welcome!

Question by:sah18
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
  • +5

Expert Comment

by:Steve Gould
ID: 36473409
You could write a batch (bat) file to copy the file and then run it using the Task Scheduler. If you let me know the full path where the file is being copied from and the full path you'd like it copied to, I'll give you some code you can save as a batch file. Once this is done, take a look at this Microsoft article on how to configure the Task Scheduler in Windows XP:-


Expert Comment

ID: 36473429
You should be able to accomplish this with Robocopy (http://www.microsoft.com/download/en/details.aspx?displaylang=en&id=17657) and a scheduled task in Task Scheduler.

If you create a reconencting network drive with log-on credentials, you should be able to cover the login problem.

Here is another location with some helpful information about Robocopy
LVL 10

Expert Comment

ID: 36473437
What version of Powershell are you using? 1 or 2?
Creating Active Directory Users from a Text File

If your organization has a need to mass-create AD user accounts, watch this video to see how its done without the need for scripting or other unnecessary complexities.

LVL 15

Expert Comment

by:Robert Sutton Jr
ID: 36473474
Just open a new Notepad session, and input the following lines:

copy <FullSourcePath>\filename <FullDestinationPath>

Save it as 'copy.bat' or whatever name you wish. Then, add a new scheduled task, when it prompts you what app to run, Browse and select your saved batch file. Then simply tell the Task Scheduler when you want it done.
You should test it before scheduling, as the above command will run it and you'll want to ensure pathname accuracy.
Alternately, you can just put the batch file in your startup folder in Windows on the PC you want to run the task.

Hope this helps.

Expert Comment

ID: 36473513
im pretty sure that you can create a batch file for this to work so here's an article that gives you one that is very similar to want you're asking for:


I hope it helps!!!

Author Comment

ID: 36474375
I have a couple questions about the above suggestions:

1) If a user isn't logged in at the time the batch file is scheduled to run, how can we still get it to run?  Since the user needs to be authenticated (and mapped) to the share location, I'm unclear how this would work.

2)  I've never used powershell, but thought it might be a way to accomplish this.  I'm not even sure how to find it or run it, so I don't know what version it would be.

3) If I place the batch file in the startup for any user just logging in, that seems the most logical solution (as The Warlock mentioned), but I'm concerned that the domain login script (the one that does the drive mapping) won't be completed prior to this batch file attempting to run.  Is there a way to delay the batch from running immediately??  Or can a delay be written into the batch as the first line, or is there a way to test if the "S" drive exists, before doing the copy?

Thanks much for all suggestions!
LVL 23

Expert Comment

by:Danny Child
ID: 36474496
Many backup tools offer the ability to run scripts on when they start or finish...  eg ArcServe, BackupExec, and so on.
You could add the The Warlock's one-liner in there, so the copy is done whenever your backup runs - daily, I hope!

If you use full UNC paths - eg \\servername\share\folder - then you don't need to worry about mapped drives (most backup tools have pretty elevated permissions so they can get to all folders anyway).

Accepted Solution

Steve Gould earned 1200 total points
ID: 36474612
My thought was to have the batch file passing credentials to map the drive and then un-mapping it when done, using roughly this method:-

Step 1: net use z: \\server\share password /user:domain\username /persistent
Step 2:copy c:\folder\file.txt z:\folder\file.txt
Step 3:net use /delete z:

This does however mean that you'll have a batch file sitting there with a username and password in it for all to see, which does present some problems. However, if a basic user was created with minimal permissions, any potential impact could be limited.
LVL 10

Assisted Solution

wls3 earned 800 total points
ID: 36475174
Create a .ps1 (Powerhsell script) with this information below and save it as Copy-Mdb.ps1 on a network share you can access from all your machine.
copy -Path ''\\Yourshare\yourfolder\yourfile.mdb" -Destination "C:\yourfolder"

Open in new window

When you create the scheduled task create it with a user account that has the appropriate privilieges.  Under the Run textbox enter the appropriate information:
C:\WINDOWS\system32\WindowsPowerShell\v1.0\powershell.exe -ExecutionPolicy Bypass -File "\\somenetworkshare\Scripts\Daily\Copy-Mdb.ps1" -NoProfile -WindowStyle "Hidden"

Open in new window

By saving scripts to a commonly accessible share you save yourself the trouble of having to put the script on multiple machines.  Additionally, you can refer to powershell -? in any shell to get more details on the switches available to starting powershell.exe.

Expert Comment

ID: 36478700
I'm amazed nobody mentioned setting up a login script. Very simple, create a GPO that targets all of the specific groups/users and then point them to a login script to copy the file over. Below is a sample script you can use to accomplish the task
copy \\server\share\example.mdb c:\database\example.mdb /Y

Open in new window


Author Comment

ID: 36546728
I apologize for not replying back sooner.  I have been swamped and have not yet had a chance to try any of your suggestions.  I'm hoping to get back to this issue in the next week & will provide feedback then.

Featured Post

Are You Ready for GDPR?

With the GDPR deadline set for May 25, 2018, many organizations are ill-prepared due to uncertainty about the criteria for compliance. According to a recent WatchGuard survey, a staggering 37% of respondents don't even know if their organization needs to comply with GDPR. Do you?

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A quick Powershell script I wrote to find old program installations and check versions of a specific file across the network.
Auditing domain password hashes is a commonly overlooked but critical requirement to ensuring secure passwords practices are followed. Methods exist to extract hashes directly for a live domain however this article describes a process to extract u…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

650 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question