Windows 7 Forums
Welcome to Windows 7 Forums. Our forum is dedicated to helping you find support and solutions for any problems regarding your Windows 7 PC be it Dell, HP, Acer, Asus or a custom build. We also provide an extensive Windows 7 tutorial section that covers a wide range of tips and tricks.


Windows 7: VBS script used to overwrite, now makes (unwanted) copy

19 Jun 2012   #1

Windows 7 Professional 32 bit
 
 
VBS script used to overwrite, now makes (unwanted) copy

I have a simple VBS login script for all my users that checks a location on our server and updates (by overwriting) the same files on the users' PCs if the server copy is newer (FSO.CopyFile etc). This has run swimmingly for several months now, but today I discovered it ISN'T overwriting the local files, but rather creates a copy of any replaced file, in the standard Win 7 format of Filename - Copy.ext.

Is this some Windows component with its Mom Switch set on high, trying to be helpful/protective? The problem it creates is this: some of the files the script updates are VBA add-ins containing a suite of Word macros; and if 2 files in the macro-supplying folder contain same-named macros, *neither* macro of the conflicting pair is available to the user.

This is a recent change -- that is, itís not something that's been happening all along but only recently noticed.

Even stranger -- or perhaps this is a clue -- this *doesn't* happen on my home PC, which is identically equpped except for different AV programs (work=Comodo, home=Avast).

All PCs are Win 7 Pro 32-bit with Office 2010.

Any ideas? I know I could change the script to delete the to-be-updated files before overwriting, but that seems like surrendering to the vampire.


My System SpecsSystem Spec
.

19 Jun 2012   #2

Windows 8.1 Pro RTM x64
 
 

Can you post a copy of the code (in text form) so that we can look at it to see if there's anything that may be causing this issue?
My System SpecsSystem Spec
19 Jun 2012   #3

Windows 7 Professional 32 bit
 
 

It's below. I hope it's decipherable but I fear it may not be. (I'm not so diligent about commenting code.) FYI the notation 'AAI' is just our shorthand for the name of the macro suite. The 'guts' of the code begins after the 'copy or update files' comment.

Code:
   Dim oFSO 
   Dim oShell
   Dim oAppDataFolder

   Set oFSO=CreateObject("Scripting.FileSystemObject")
   Set oServerUT = oFSO.GetFolder("Z:\Users\AAI\UT\")
   Set oServerSU = oFSO.GetFolder("Z:\Users\AAI\SU\")
   Set oShell = CreateObject("Shell.Application")
   Set oAppDataFolder = oShell.Namespace(&H1a&)

   WSF = oAppDataFolder.Self.Path & "\Microsoft\Word\Startup\"

   Set oShell2 = CreateObject("WScript.Shell")
   Hpath = oShell2.ExpandEnvironmentStrings("%HomePath%")
   
   '===set local AAI file path
   sAAI = "C:" & Hpath & "\AAI\"
   sAAIUT = sAAI & "UT"
   Set oAAI = oFSO.GetFolder(sAAI)
   Set oUserUT = oFSO.GetFolder(sAAIUT)

   '====copy or update files
   Set colFilesUT = oServerUT.Files
   For Each oFile In colFilesUT
      If Instr(oFile.Name,"~")=0 Then
         sLocal = Right(oFile, Len(oFile.Name) - InStrRev(oFile.Name, "\"))
         If Not oFSO.FileExists(oUserUT.Path & "\" & sLocal) Then
            'not found on local PC, so copy
            oFSO.CopyFile oFile.Path, oUserUT.Path & "\"
            bUpdated = True
         Else
            Set oLocalFile = oFSO.GetFile(oUserUT.Path & "\" & oFile.Name)
            If oFile.DateLastModified > oLocalFile.DateLastModified Then
              'found older on local PC, so replace
               oFSO.CopyFile oFile.Path, oUserUT.Path & "\"
               bUpdated = True
            End If 
         End If
      End If
   Next

   Set colFilesSU = oServerSU.Files
   For Each oFile In colFilesSU
      If Instr(oFile.Name,"~")=0 Then
         sLocal = Right(oFile, Len(oFile.Name) - InStrRev(oFile.Name, "\"))
         If Not oFSO.FileExists(WSF & sLocal) Then
            'not found on local PC, so copy
            oFSO.CopyFile oFile.Path, WSF
            bUpdated = True
         Else
            Set oLocalFile = oFSO.GetFile(WSF & oFile.Name)
            If oFile.DateLastModified > oLocalFile.DateLastModified Then 
               'found older on local PC, so replace
               oFSO.CopyFile oFile.Path, WSF
               bUpdated = True
            End If 
         End If
      End If 
   Next

   On Error Resume Next 
   Set oShell = Nothing
   Set oShell2 = Nothing 
   Set oFSO = Nothing
   Set oAppDataFolder = Nothing
   Set oServerUT = Nothing
   Set oUserUT = Nothing
   Set SystemSet = Nothing
   Set oAAI = Nothing
   Set oHT = Nothing
   Set colFilesUT = Nothing 
   Set colFilesSU = Nothing 
   Set oLocalFile = Nothing
   If bNewInstall = True Then 
      MsgBox "Install successful."
   End If
My System SpecsSystem Spec
.


19 Jun 2012   #4

Windows 7 Ultimate x64 SP1 clean install
 
 

Hi, the method CopyFile has a third parameter, overwrite. If it is true, it'll overwrite the file:
Code:
oFSO.CopyFile source, destination, True
Another recommendation: as destination, don't use only path, but include also the filename (i.e., not C:\Temp but C:\Temp\MyFile).

CyberZeus
My System SpecsSystem Spec
19 Jun 2012   #5

Windows 7 Professional 32 bit
 
 

Thanks. That's interesting. But is there a reason this third parameter would be required on some systems and not others? (The differently-behaving machines are very similar, even similar Dell models purchased the same month!)

I appreciate the tip.
My System SpecsSystem Spec
19 Jun 2012   #6

Windows 7 Ultimate x64 SP1 clean install
 
 

You're welcome!

I don't know why the behaviour is different, however if the third parameter solves, use it.

CyberZeus
My System SpecsSystem Spec
Reply

 VBS script used to overwrite, now makes (unwanted) copy




Thread Tools



Similar help and support threads for2: VBS script used to overwrite, now makes (unwanted) copy
Thread Forum
Windows Backup makes unwanted folders on all drives, want deleted Backup and Restore
Keystroke overload for mass-copy overwrite (among others) General Discussion
I Need Help To Reorder The Context Menu Script In Script Form? Customization
VBS script: Cannot find script engine General Discussion
Overwrite -- without Prompts General Discussion
script error when running a vbs script. Network & Sharing
How Can I Overwrite Drive With Win 7 32 bit to 64 bit Installation & Setup

Our Sites

Site Links

About Us

Find Us

Windows 7 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 7" and related materials are trademarks of Microsoft Corp.

© Designer Media Ltd

All times are GMT -5. The time now is 12:28 PM.
Twitter Facebook Google+



Windows 7 Forums

Seven Forums Android App Seven Forums IOS App
  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33