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
mark99k

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
Dwarf

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
mark99k

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
CyberZeus

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
mark99k

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
CyberZeus

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
Thread Forum
BAT Script to Copy Most Recent File from One shared to Another
Hi, Please help me in creating a batch file to copy file from one shared location to another. ( I have no knowledge about batch files) I have a folder that has more than 3000 sub folders, each sub folder having 1 or more files. I want to copy only few sub folders to my destination location....
General Discussion
How to script a daily copy of files w/dt being name of archive folder
Hello, I need to figure out a Windows 7 script to copy/archive files which are located in a specific folder. It needs to copy daily to an archive folder, with the script creating the archive folder as MM-DD-YY (being that day's date that is being archived) before it archives the files to that...
General Discussion
Windows Backup makes unwanted folders on all drives, want deleted
I've had my machine for quite some time now, and I just now got my hard drive set up for Windows backup. When I go to the root of a hard drive, not just my backup HDD, but every external and internal hard drive (other than the bootable), there will be an empty folder labeled, "Music." I have no...
Backup and Restore
Keystroke overload for mass-copy overwrite (among others)
I'm always astounded at how much more keyboard-hostile each new version of Windows seems to be -- starting with hidden accelerators back in, what was it, ought-2? Is there a hack or workaround to bring back 'Yes To All' when copying files whose names may collide with their targets? The only...
General Discussion
Overwrite -- without Prompts
I have to Overwrite all day long, lots and lot of files. 2 issues. 1. every time I overwrite, I have to go throught the several prompt dialogs --- how to avoid??? 2. i just did an overwrite from one drive to another and it appears to have merged rather than full overwrite?
General Discussion
How Can I Overwrite Drive With Win 7 32 bit to 64 bit
I've got a single hard drive with WIN 7 32 bit RC operating OK. I want to replace it with WIN 7 64 bit RC (not dual boot). I inserted the 64 bit DVD WIN 7 install ISO disk in my DVD and either it will boot me into by 32 bit system or gives me options to repair it. But, no options to overwrite...
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 00:10.

Twitter Facebook Google+



Windows 7 Forums

Seven Forums Android App Seven Forums IOS App