I have a simple script that maps a shared folder from one of our servers. And then move all the files from one of the folders in it to the local machine. I created an entry in windows scheduler to run this script every 10 minutes. The script works fine when I am logged in the machine.
The problem that I have is that, the script doesnt move the files when I am not logged in the machine.
I did a lot of searching but have not found any solution to this yet. Thanks for your help in advance.
Below is my script.
Set objNetwork = CreateObject("WScript.Network")
sUserName = objNetwork.UserName
Dim aNetworkDrives(4, 2)
aNetworkDrives(0, 0) = "Z:"
aNetworkDrives(0, 1) = "<a href="file://pronto.grahamgroup.local/gdb">\\pronto.grahamgroup.local\gdb</a>"
sPersistent = "FALSE"
sUsername = "MyUserNameHere"
sPassword = "MyPasswordHere"
Set oCheckDrive = objNetwork.EnumNetworkDrives()
On Error Resume Next
For iNetDriveCounter = 0 To Ubound(aNetworkDrives, 1) - 1 Step 1
bAlreadyConnected = False
For iCheckCounter = 0 To oCheckDrive.Count - 1 Step 1
IF oCheckDrive.Item(iCheckCounter) = aNetworkDrives(iNetDriveCounter, 0) THEN
bAlreadyConnected = True
END IF
Next
IF bAlreadyConnected = False THEN
objNetwork.MapNetworkDrive aNetworkDrives(iNetDriveCounter, 0),
aNetworkDrives(iNetDriveCounter, 1), sPersistent, sUsername, sPassword
END IF
Next
sSource= "Z:\francistestfolder"
sDestination= "C:\Documents and Settings\francisp\Desktop\test map\b\"
getFolder sSource, sDestination
Function getFolder(ByVal sSource, ByVal sDestination)
Dim fso, file, files
Set fso = CreateObject("Scripting.FileSystemObject")
If fso.FolderExists(sSource) Then
For Each file In fso.GetFolder(sSource).Files
sDestinationFileName = sDestination & file.Name
If fso.FileExists(sDestinationFileName) Then
sDestinationFileName = RenameFile(sDestinationFileName)
End If
file.Move(sDestinationFileName)
Next
Else
Exit Function
End If
End Function
Function RenameFile(ByVal sFileName)
RenameFile = sFileName & Year(Now) & Month(Now) & Day(Now) & Hour(Now) &
Minute(Now) & Second(Now)
End Function