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!
Latest posts by Andy Parkes (see all)
- Running Gear – AfterShokz Trekz Titanium - November 24, 2019
- Windows App Store – “Where do you want to install” - September 6, 2019
- Amazon Fulfilment Centre Tour - April 16, 2019