Professional Geek
RSS icon Email icon Bullet (black)
  • Doh!

    Posted on October 25th, 2006 Andy Parkes No comments

    Ever feel stupid?

    I have a vbscript that copies a series of files from one server to another (don’t ask why!) that runs using a scheduled task

    Now if i run the script manually all works fine. If i run the scheduled task manually all works fine.

    However, every week when i expect the data to have been copied nothing happens

    I’ve simplified the code for posting purposes as the code also does some logging and error checking

    SourceFolderPath = “S:\Images\System\”
    DestinationFolderPath =”E:\images\TempArea\” 

    set FSO = CreateObject(“Scripting.FileSystemObject”)

    set SourceFolderObj = FSO.GetFolder(SourceFolderPath)
    Set DestinationFolderObj = FSO.GetFolder(DestinationFolderPath)
    ”Empty Destination Directory

    For each LoopFile in DestinationFolderObj.Files
    LoopName = LoopFile.name
    LoopFile.Delete
    next

     ”Transfer files

    For each LoopFile in SourceFolderObj.Files

    LoopFile.Copy(DestinationFolderPath)

    Next

    Can anyone tell me why this fails?

    I had a eureka moment this morning

    The source folder is on drive S:

    Which exists when i run the script manually. But it doesn’t exist when i’m logged off

    So i added the following

    strDriveLetter = “S:”
    strRemotePath = “\\Server\Share
    strUser = “someuser”
    strPassword = “somepassword”     
    strProfile = “false”

    Set objNetwork = WScript.CreateObject(“WScript.Network”)
    objNetwork.MapNetworkDrive strDriveLetter, strRemotePath,strProfile, strUser, strPassword

    And volia!

    Not entirely sure why i didn’t spot this earlier but needless to say when i did i felt like giving myself a kick!

    The following two tabs change content below.
    Andy Parkes is Technical Director at Coventry based IT support company IBIT Solutions. He is also Microsoft Partner Area Lead for 2012-2013 and coordinates AMITPRO which is a peer group for IT Professionals in the Midlands area. He also isn't a fan of describing himself in the third person.

    Latest posts by Andy Parkes (see all)

    Leave a Reply