kwatt562
asked on
Copy files from network shares using a vbs script
Hi
Is there a way to modify the below script to include a specific username and password (this user account will have permisiions to access both the source and destination network shares. Thanks
Dim sOriginFolder, sDestinationFolder, sFile, oFSO, oShell
Set oFSO = CreateObject("Scripting.Fi leSystemOb ject")
Set oShell = CreateObject("Wscript.Shel l")
sOriginFolder = "networkfoldera"
sDestinationFolder = "networkfolderb"
On Error Resume Next
sLastTime = oShell.RegRead("HKLM\SYSTE M\LastTime Copied")
iErr = Err.Number
On Error GoTo 0
If iErr <> 0 Then
oShell.RegWrite "HKLM\SYSTEM\LastTimeCopie d",Now,"RE G_SZ"
Call CopyFiles("ALL")
Else
oShell.RegWrite "HKLM\SYSTEM\LastTimeCopie d",Now,"RE G_SZ"
Call CopyFiles(sLastTime)
End If
Sub CopyFiles(sArg)
If sArg = "ALL" Then
For Each sFile In oFSO.GetFolder(sOriginFold er).Files
If Not oFSO.FileExists(sDestinati onFolder & "\" & oFSO.GetFileName(sFile)) Then
oFSO.GetFile(sFile).Copy sDestinationFolder & "\" & oFSO.GetFileName(sFile),Tr ue
End If
Next
Else
For Each sFile In oFSO.GetFolder(sOriginFold er).Files
If Not oFSO.FileExists(sDestinati onFolder & "\" & oFSO.GetFileName(sFile)) Then
If DateDiff("s",sLastTime,oFS O.GetFile( sFile).Dat eCreated) > 0 Then
oFSO.GetFile(sFile).Copy sDestinationFolder & "\" & oFSO.GetFileName(sFile),Tr ue
End If
End If
Next
End If
Is there a way to modify the below script to include a specific username and password (this user account will have permisiions to access both the source and destination network shares. Thanks
Dim sOriginFolder, sDestinationFolder, sFile, oFSO, oShell
Set oFSO = CreateObject("Scripting.Fi
Set oShell = CreateObject("Wscript.Shel
sOriginFolder = "networkfoldera"
sDestinationFolder = "networkfolderb"
On Error Resume Next
sLastTime = oShell.RegRead("HKLM\SYSTE
iErr = Err.Number
On Error GoTo 0
If iErr <> 0 Then
oShell.RegWrite "HKLM\SYSTEM\LastTimeCopie
Call CopyFiles("ALL")
Else
oShell.RegWrite "HKLM\SYSTEM\LastTimeCopie
Call CopyFiles(sLastTime)
End If
Sub CopyFiles(sArg)
If sArg = "ALL" Then
For Each sFile In oFSO.GetFolder(sOriginFold
If Not oFSO.FileExists(sDestinati
oFSO.GetFile(sFile).Copy sDestinationFolder & "\" & oFSO.GetFileName(sFile),Tr
End If
Next
Else
For Each sFile In oFSO.GetFolder(sOriginFold
If Not oFSO.FileExists(sDestinati
If DateDiff("s",sLastTime,oFS
oFSO.GetFile(sFile).Copy sDestinationFolder & "\" & oFSO.GetFileName(sFile),Tr
End If
End If
Next
End If
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.