Link to home
Start Free TrialLog in
Avatar of kwatt562
kwatt562Flag for United Kingdom of Great Britain and Northern Ireland

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.FileSystemObject")
 Set oShell = CreateObject("Wscript.Shell")
 sOriginFolder = "networkfoldera"
 sDestinationFolder = "networkfolderb"
 On Error Resume Next  
  sLastTime = oShell.RegRead("HKLM\SYSTEM\LastTimeCopied")
  iErr = Err.Number
 On Error GoTo 0
  If iErr <> 0 Then
   oShell.RegWrite "HKLM\SYSTEM\LastTimeCopied",Now,"REG_SZ"
   Call CopyFiles("ALL")
  Else
   oShell.RegWrite "HKLM\SYSTEM\LastTimeCopied",Now,"REG_SZ"
   Call CopyFiles(sLastTime)
  End If  
   
 Sub CopyFiles(sArg)
   If sArg = "ALL" Then
     For Each sFile In oFSO.GetFolder(sOriginFolder).Files
       If Not oFSO.FileExists(sDestinationFolder & "\" & oFSO.GetFileName(sFile)) Then
         oFSO.GetFile(sFile).Copy sDestinationFolder & "\" & oFSO.GetFileName(sFile),True
        End If
     Next
   Else
     For Each sFile In oFSO.GetFolder(sOriginFolder).Files
       If Not oFSO.FileExists(sDestinationFolder & "\" & oFSO.GetFileName(sFile)) Then
         If DateDiff("s",sLastTime,oFSO.GetFile(sFile).DateCreated) > 0 Then  
           oFSO.GetFile(sFile).Copy sDestinationFolder & "\" & oFSO.GetFileName(sFile),True
           
          End If
       End If  
     Next  
   End If  
ASKER CERTIFIED SOLUTION
Avatar of RobSampson
RobSampson
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial